Browse Source

fix test + test new string litearls

Getty Ritter 2 years ago
parent
commit
06d652d9de
3 changed files with 55 additions and 6 deletions
  1. 3 2
      build.rs
  2. 9 4
      tests/str_lit.matzo
  3. 43 0
      tests/str_lit.parsed

+ 3 - 2
build.rs

@@ -6,7 +6,7 @@ use std::path::Path;
 const TEST_PREFIX: &str = "
 #[cfg(test)]
 use pretty_assertions::assert_eq;
-use crate::grammar;
+use crate::{grammar,lexer};
 use std::io::Write;
 
 // to let us use pretty_assertions with strings, we write a newtype
@@ -31,7 +31,8 @@ const TEST_TEMPLATE: &str = "
 #[test]
 fn test_%PREFIX%() {
   let source = include_str!(\"%ROOT%/tests/%PREFIX%.matzo\");
-  let ast = grammar::StmtsParser::new().parse(source);
+  let lexer = lexer::tokens(source);
+  let ast = grammar::StmtsParser::new().parse(lexer);
   assert!(ast.is_ok());
   let ast = ast.unwrap();
 

+ 9 - 4
tests/str_lit.matzo

@@ -1,10 +1,15 @@
 (* basic string literals *)
-puts 'foo';
+puts 'foo' "foo";
 (* string literals with spaces *)
-puts 'foo bar baz';
+puts 'foo bar baz' "foo bar baz";
 
 (* string literals with escaped quotes *)
-puts 'won\'t you';
+puts
+  'won\'t you'
+  "quoth the raven \"nevermore\"";
 
 (* string literals with escaped newlines *)
-puts 'this\nthat';
+puts 'this\nthat' "one\ntwo";
+
+(* various escapes *)
+puts '\n\t\r' "\n\t\r";

+ 43 - 0
tests/str_lit.parsed

@@ -11,6 +11,11 @@
                                     "foo",
                                 ),
                             ),
+                            Lit(
+                                Str(
+                                    "foo",
+                                ),
+                            ),
                         ],
                     ),
                 },
@@ -29,6 +34,11 @@
                                     "foo bar baz",
                                 ),
                             ),
+                            Lit(
+                                Str(
+                                    "foo bar baz",
+                                ),
+                            ),
                         ],
                     ),
                 },
@@ -47,6 +57,11 @@
                                     "won't you",
                                 ),
                             ),
+                            Lit(
+                                Str(
+                                    "quoth the raven \"nevermore\"",
+                                ),
+                            ),
                         ],
                     ),
                 },
@@ -65,6 +80,34 @@
                                     "this\nthat",
                                 ),
                             ),
+                            Lit(
+                                Str(
+                                    "one\ntwo",
+                                ),
+                            ),
+                        ],
+                    ),
+                },
+            ],
+        ),
+    ),
+    Puts(
+        Chc(
+            [
+                Choice {
+                    weight: None,
+                    value: Cat(
+                        [
+                            Lit(
+                                Str(
+                                    "\n\t\r",
+                                ),
+                            ),
+                            Lit(
+                                Str(
+                                    "\n\t\r",
+                                ),
+                            ),
                         ],
                     ),
                 },