tests: added tons of tests for kdl

This commit is contained in:
felipegchi 2022-11-29 13:45:33 -03:00
parent 6844cc2735
commit df27bb8190
30 changed files with 186 additions and 1 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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)
}

View 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(())
}

View File

@ -0,0 +1 @@
300

View 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))

View File

@ -0,0 +1 @@
700

View 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

View File

@ -0,0 +1,3 @@
#kdl_name = JOJO
Jonathan.Joestar : U60
Jonathan.Joestar = 42

View File

@ -0,0 +1,8 @@
CoolFn : U60 -> U60 {
(x: U60) => (* 2 x)
}
CoolFnApp (n: U60) : U60 {
let lam = (x: U60) => ((CoolFn) x)
(lam n)
}

View File

@ -0,0 +1 @@
ctr {MyFn.state}

View File

@ -0,0 +1,6 @@
#kdl_state = MyFn.state
MyFn : U60 {
1
}
MyFn.state : U60

View 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)
}

View 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)))))))))))))))

View 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
*/

View File

@ -0,0 +1,10 @@
fun (A ) {
{A} = #2
}
run {
(A)
}
run {
#4
}

View 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

View File

@ -0,0 +1,3 @@
FunctionWithAVeryLongName : U60 {
0
}

View File

@ -0,0 +1,4 @@
fun (A ) {
{A} = (& (+ (B) #1) #1152921504606846975)
}

View File

@ -0,0 +1,11 @@
#kdl_name = A
#keep
FnA {
(+ FnB 1)
}
#kdl_name = B
#kdl_erase
FnB {
2
}

View File

@ -0,0 +1,3 @@
run {
#2
}

View File

@ -0,0 +1,4 @@
#kdl_run
#keep
Main: U60
Main = 2

View File

@ -0,0 +1,3 @@
run {
#0
}

View File

@ -0,0 +1,9 @@
#kdl_state = MyFn.state
MyFn : U60 {
1
}
#kdl_run
MyFn.state : U60 {
0
}

View File

@ -0,0 +1,4 @@
type String {
cons (x: U60) (xs: String)
nil
}

View File

@ -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.