mirror of
https://github.com/HigherOrderCO/Kind1.git
synced 2024-10-26 13:38:47 +03:00
tests: added tons of tests for kdl
This commit is contained in:
parent
6844cc2735
commit
df27bb8190
@ -44,6 +44,11 @@ impl<'a> DesugarState<'a> {
|
||||
self.attr_without_value(attr);
|
||||
attributes.inlined = true;
|
||||
}
|
||||
"keep" => {
|
||||
self.args_should_be_empty(attr);
|
||||
self.attr_without_value(attr);
|
||||
attributes.keep = true;
|
||||
}
|
||||
"kdl_run" => {
|
||||
self.args_should_be_empty(attr);
|
||||
self.attr_without_value(attr);
|
||||
|
@ -123,7 +123,7 @@ impl<'a> ErasureState<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
if entr.attrs.kdl_run {
|
||||
if entr.attrs.kdl_run || entr.attrs.keep {
|
||||
let id = self.get_edge_or_create(&entr.name);
|
||||
self.set_relevance(id, Relevance::Relevant, entr.name.range);
|
||||
entrypoints.push(id);
|
||||
|
@ -22,6 +22,9 @@ pub fn compile_book(
|
||||
let flattened = flatten(book);
|
||||
|
||||
let file = compile::compile_book(&flattened, sender, namespace)?;
|
||||
|
||||
println!("{}", file);
|
||||
|
||||
let file = linearize::linearize_file(file);
|
||||
Some(file)
|
||||
}
|
||||
|
@ -102,3 +102,38 @@ fn test_eval() -> Result<(), Error> {
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
#[timeout(15000)]
|
||||
fn test_kdl() -> Result<(), Error> {
|
||||
test_kind2(Path::new("./tests/suite/kdl"), |path| {
|
||||
let (rx, tx) = std::sync::mpsc::channel();
|
||||
let root = PathBuf::from("./tests/suite/lib").canonicalize().unwrap();
|
||||
let mut session = Session::new(root, rx);
|
||||
|
||||
let entrypoints = vec!["Main".to_string()];
|
||||
let check = driver::compile_book_to_kdl(&PathBuf::from(path), &mut session, "", entrypoints);
|
||||
|
||||
let diagnostics = tx.try_iter().collect::<Vec<_>>();
|
||||
let render = RenderConfig::ascii(2);
|
||||
|
||||
kind_report::check_if_colors_are_supported(true);
|
||||
|
||||
match check {
|
||||
Some(file) if diagnostics.is_empty() => {
|
||||
file.to_string()
|
||||
}
|
||||
_ => {
|
||||
let mut res_string = String::new();
|
||||
|
||||
for diag in diagnostics {
|
||||
diag.render(&mut session, &render, &mut res_string).unwrap();
|
||||
}
|
||||
|
||||
res_string
|
||||
}
|
||||
}
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
1
crates/kind-tests/tests/suite/eval/Getters.golden
Normal file
1
crates/kind-tests/tests/suite/eval/Getters.golden
Normal file
@ -0,0 +1 @@
|
||||
300
|
10
crates/kind-tests/tests/suite/eval/Getters.kind2
Normal file
10
crates/kind-tests/tests/suite/eval/Getters.kind2
Normal file
@ -0,0 +1,10 @@
|
||||
#derive[getters]
|
||||
record Pair (a: Type) (b: Type) {
|
||||
fst : a
|
||||
snd : b
|
||||
}
|
||||
|
||||
Main : U60
|
||||
Main =
|
||||
let a = (Pair.new 100 200 :: Pair U60 U60)
|
||||
(+ (Pair.fst.get a) (Pair.snd.get a))
|
1
crates/kind-tests/tests/suite/eval/Setters.golden
Normal file
1
crates/kind-tests/tests/suite/eval/Setters.golden
Normal file
@ -0,0 +1 @@
|
||||
700
|
12
crates/kind-tests/tests/suite/eval/Setters.kind2
Normal file
12
crates/kind-tests/tests/suite/eval/Setters.kind2
Normal file
@ -0,0 +1,12 @@
|
||||
#derive[getters, setters]
|
||||
record Pair (a: Type) (b: Type) {
|
||||
fst : a
|
||||
snd : b
|
||||
}
|
||||
|
||||
Main : U60
|
||||
Main =
|
||||
let a = (Pair.new 100 200 :: Pair U60 U60)
|
||||
let b = Pair.fst.set a 500
|
||||
let c = Pair.snd.set a (+ (Pair.fst.get b) (Pair.snd.get b))
|
||||
Pair.snd.get c
|
0
crates/kind-tests/tests/suite/kdl/ChangeName.golden
Normal file
0
crates/kind-tests/tests/suite/kdl/ChangeName.golden
Normal file
3
crates/kind-tests/tests/suite/kdl/ChangeName.kind2
Normal file
3
crates/kind-tests/tests/suite/kdl/ChangeName.kind2
Normal file
@ -0,0 +1,3 @@
|
||||
#kdl_name = JOJO
|
||||
Jonathan.Joestar : U60
|
||||
Jonathan.Joestar = 42
|
0
crates/kind-tests/tests/suite/kdl/Lambda.golden
Normal file
0
crates/kind-tests/tests/suite/kdl/Lambda.golden
Normal file
8
crates/kind-tests/tests/suite/kdl/Lambda.kind2
Normal file
8
crates/kind-tests/tests/suite/kdl/Lambda.kind2
Normal file
@ -0,0 +1,8 @@
|
||||
CoolFn : U60 -> U60 {
|
||||
(x: U60) => (* 2 x)
|
||||
}
|
||||
|
||||
CoolFnApp (n: U60) : U60 {
|
||||
let lam = (x: U60) => ((CoolFn) x)
|
||||
(lam n)
|
||||
}
|
1
crates/kind-tests/tests/suite/kdl/NonInlineState.golden
Normal file
1
crates/kind-tests/tests/suite/kdl/NonInlineState.golden
Normal file
@ -0,0 +1 @@
|
||||
ctr {MyFn.state}
|
6
crates/kind-tests/tests/suite/kdl/NonInlineState.kind2
Normal file
6
crates/kind-tests/tests/suite/kdl/NonInlineState.kind2
Normal file
@ -0,0 +1,6 @@
|
||||
#kdl_state = MyFn.state
|
||||
MyFn : U60 {
|
||||
1
|
||||
}
|
||||
|
||||
MyFn.state : U60
|
3
crates/kind-tests/tests/suite/kdl/Operators.golden
Normal file
3
crates/kind-tests/tests/suite/kdl/Operators.golden
Normal file
@ -0,0 +1,3 @@
|
||||
run {
|
||||
(& (+ #2 (& (- #3 (& (* #4 (/ #5 (% #6 (& (+ #2 (| #8 (^ #9 (<< #10 (% (>> #23 (% (< #2 (>= #4 (<= (== #4 #4) (> #3 (!= #5 #3))))) #60)) #60))))) #1152921504606846975)))) #1152921504606846975)) #1152921504606846975)) #1152921504606846975)
|
||||
}
|
18
crates/kind-tests/tests/suite/kdl/Operators.kind2
Normal file
18
crates/kind-tests/tests/suite/kdl/Operators.kind2
Normal file
@ -0,0 +1,18 @@
|
||||
#kdl_run
|
||||
Main : U60
|
||||
Main =
|
||||
(+ 2
|
||||
(- 3
|
||||
(* 4
|
||||
(/ 5
|
||||
(% 6
|
||||
(& 2
|
||||
(| 8
|
||||
(^ 9
|
||||
(<< 10
|
||||
(>> 23
|
||||
(< 2
|
||||
(>= 4
|
||||
(<= (== 4 4)
|
||||
(> 3
|
||||
(!= 5 3)))))))))))))))
|
14
crates/kind-tests/tests/suite/kdl/RemoveNames.kind2
Normal file
14
crates/kind-tests/tests/suite/kdl/RemoveNames.kind2
Normal file
@ -0,0 +1,14 @@
|
||||
List <a> : Type
|
||||
List.nil <a> : List
|
||||
List.cons <a> (head: a) (tail: List a) : List
|
||||
|
||||
/*
|
||||
#keep
|
||||
Ora.Ora.ora (h: List U60) : List U60
|
||||
Ora.Ora.ora (List.cons x xs) =
|
||||
let aaa = 2
|
||||
let bbb = 3
|
||||
let ccc = 4
|
||||
let ddd = (+ ccc bbb)
|
||||
List.cons aaa xs
|
||||
*/
|
10
crates/kind-tests/tests/suite/kdl/Run.golden
Normal file
10
crates/kind-tests/tests/suite/kdl/Run.golden
Normal file
@ -0,0 +1,10 @@
|
||||
fun (A ) {
|
||||
{A} = #2
|
||||
}
|
||||
|
||||
run {
|
||||
(A)
|
||||
}
|
||||
run {
|
||||
#4
|
||||
}
|
13
crates/kind-tests/tests/suite/kdl/Run.kind2
Normal file
13
crates/kind-tests/tests/suite/kdl/Run.kind2
Normal file
@ -0,0 +1,13 @@
|
||||
#kdl_name = A
|
||||
Ata : U60
|
||||
Ata = 2
|
||||
|
||||
#kdl_name = B
|
||||
#kdl_run
|
||||
Be : U60
|
||||
Be = Ata
|
||||
|
||||
#kdl_name = C
|
||||
#kdl_run
|
||||
Ce : U60
|
||||
Ce = 4
|
0
crates/kind-tests/tests/suite/kdl/Shortener.golden
Normal file
0
crates/kind-tests/tests/suite/kdl/Shortener.golden
Normal file
3
crates/kind-tests/tests/suite/kdl/Shortener.kind2
Normal file
3
crates/kind-tests/tests/suite/kdl/Shortener.kind2
Normal file
@ -0,0 +1,3 @@
|
||||
FunctionWithAVeryLongName : U60 {
|
||||
0
|
||||
}
|
4
crates/kind-tests/tests/suite/kdl/StillCalable.golden
Normal file
4
crates/kind-tests/tests/suite/kdl/StillCalable.golden
Normal file
@ -0,0 +1,4 @@
|
||||
fun (A ) {
|
||||
{A} = (& (+ (B) #1) #1152921504606846975)
|
||||
}
|
||||
|
11
crates/kind-tests/tests/suite/kdl/StillCalable.kind2
Normal file
11
crates/kind-tests/tests/suite/kdl/StillCalable.kind2
Normal file
@ -0,0 +1,11 @@
|
||||
#kdl_name = A
|
||||
#keep
|
||||
FnA {
|
||||
(+ FnB 1)
|
||||
}
|
||||
|
||||
#kdl_name = B
|
||||
#kdl_erase
|
||||
FnB {
|
||||
2
|
||||
}
|
3
crates/kind-tests/tests/suite/kdl/U60.golden
Normal file
3
crates/kind-tests/tests/suite/kdl/U60.golden
Normal file
@ -0,0 +1,3 @@
|
||||
run {
|
||||
#2
|
||||
}
|
4
crates/kind-tests/tests/suite/kdl/U60.kind2
Normal file
4
crates/kind-tests/tests/suite/kdl/U60.kind2
Normal file
@ -0,0 +1,4 @@
|
||||
#kdl_run
|
||||
#keep
|
||||
Main: U60
|
||||
Main = 2
|
3
crates/kind-tests/tests/suite/kdl/WithAttr.golden
Normal file
3
crates/kind-tests/tests/suite/kdl/WithAttr.golden
Normal file
@ -0,0 +1,3 @@
|
||||
run {
|
||||
#0
|
||||
}
|
9
crates/kind-tests/tests/suite/kdl/WithAttr.kind2
Normal file
9
crates/kind-tests/tests/suite/kdl/WithAttr.kind2
Normal file
@ -0,0 +1,9 @@
|
||||
#kdl_state = MyFn.state
|
||||
MyFn : U60 {
|
||||
1
|
||||
}
|
||||
|
||||
#kdl_run
|
||||
MyFn.state : U60 {
|
||||
0
|
||||
}
|
4
crates/kind-tests/tests/suite/lib/String.kind2
Normal file
4
crates/kind-tests/tests/suite/lib/String.kind2
Normal file
@ -0,0 +1,4 @@
|
||||
type String {
|
||||
cons (x: U60) (xs: String)
|
||||
nil
|
||||
}
|
@ -32,6 +32,7 @@ pub struct Attributes {
|
||||
pub kdl_name: Option<Ident>,
|
||||
pub kdl_state: Option<Ident>,
|
||||
pub trace: Option<bool>, // Some is enabled and some(true) is enabled with arguments
|
||||
pub keep: bool
|
||||
}
|
||||
|
||||
/// Enum of binary operators.
|
||||
|
Loading…
Reference in New Issue
Block a user