use ngc::parse;
#[test]
fn test_parse() {
let src = r#"; Try to exercise as much of the syntax as possible.
; comments anywhere, line numbers, and block deletion
/G1 X1 0(a)(b) Y2(a);rest
/(a)
(a)N1 G#1 X-[10] (a)
; number formats
#1=+1. (a) #2=1.5 #3=-.5
; expressions
G[[1+ 2]/ 3*4--5]
G+SIN[0]
G[ATAN[1]/[2]]
G[1 LE 2]
; parameter references
#1=[1+2]
#<de pth>=1
#<de(a) pth>=2
#[1 ]=3
#-#2=[+ 5]
#SIN [0]=7 ; LCNC doesn't like this.
# 10 = EXISTS[#<blub>]
"#;
let parsed = r#"/ G1 X10 Y2
G#1 X-10
#1=1 #2=1.5 #3=-0.5
G[[[[1 + 2] / 3] * 4] - -5]
GSIN[0]
GATAN[1]/[2]
G[1 LE 2]
#1=[1 + 2]
#<depth>=1
#<de(a)pth>=2
#1=3
#-#2=5
#[SIN[0]]=7
#10=EXISTS[#<blub>]
"#;
let prog = parse::parse("testfile", src).unwrap();
assert_eq!(prog.blocks[0].lineno, 4);
println!("{:#?}", prog);
assert_eq!(prog.to_string(), parsed.replace("\n", " \n"));
}
#[test]
fn test_invalid() {
for snippet in &[
"$", "GG", "O10", "(", "(\n)", "G(a)1", "G1(a)2", "G[1(a)+2]", "G[1;]", "G[TEST[x]]", "#1.2=5", "#1=EXISTS[5]", ] {
assert!(parse::parse("testfile", snippet).is_err());
}
}