From 975ae0a2008709680d1ee9ec10640dc08b3a490e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 16 Jun 2015 11:34:01 -0400 Subject: [PATCH] cleanup tests a little --- src/normalize/mod.rs | 14 +------ src/normalize/tyinfer/test.rs | 70 +++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/src/normalize/mod.rs b/src/normalize/mod.rs index 6e4f5a5..297003a 100644 --- a/src/normalize/mod.rs +++ b/src/normalize/mod.rs @@ -45,21 +45,9 @@ mod macro_expand; // Computes types where the user omitted them (or from macro // byproducts). // -// AFTER THIS POINT: All explicit, simple types. +// AFTER THIS POINT: All explicit types, no `OfSymbol` types. mod tyinfer; -// Converts -// -// X = ...1 (A B C) ...2 -// -// to -// -// X = ...1 A_B_C ...2 -// A_B_C = A B C -// -// AFTER THIS POINT: No more Symbol::Expr remain. -// mod nonterminalize; - // Synthesizes action code for all nonterminals. // // AFTER THIS POINT: All nonterminals have action code, and all diff --git a/src/normalize/tyinfer/test.rs b/src/normalize/tyinfer/test.rs index 79ebb5f..0995c1f 100644 --- a/src/normalize/tyinfer/test.rs +++ b/src/normalize/tyinfer/test.rs @@ -1,32 +1,35 @@ use parser; use normalize::macro_expand::expand_macros; use normalize::tyinfer::infer_types; -use normalize::test_util::compare; +use normalize::test_util; + +fn compare(g1: &str, g2: &str) { + let actual = parser::parse_grammar(g1).unwrap(); + let actual = expand_macros(actual).unwrap(); + let actual = infer_types(actual).unwrap(); + + let expected = parser::parse_grammar(g2).unwrap(); + + test_util::compare(actual, expected); +} #[test] fn test_pairs_and_tokens() { - let grammar = parser::parse_grammar(" + compare(" grammar Foo { - token Tok where { }; + token Tok where { }; X = Y Z; Y: Foo = \"Hi\"; Z = \"Ho\"; } -").unwrap(); - - let actual = expand_macros(grammar).unwrap(); - let actual = infer_types(actual).unwrap(); - - let expected = parser::parse_grammar(" +"," grammar Foo { token Tok where { }; X: (Foo, Tok) = Y Z; Y: Foo = \"Hi\"; Z: Tok = \"Ho\"; } -").unwrap(); - - compare(actual, expected); +") } #[test] @@ -64,48 +67,51 @@ grammar Foo { #[test] fn test_macro_expansion() { - let grammar = parser::parse_grammar(" + compare(" grammar Foo { token Tok where { }; Two: (X, X) = X X; Ids = Two<\"Id\">; } -").unwrap(); - - let actual = expand_macros(grammar).unwrap(); - let actual = infer_types(actual).unwrap(); - - let expected = parser::parse_grammar(" +"," grammar Foo { token Tok where { }; Ids: (Tok, Tok) = `Two<\"Id\">`; `Two<\"Id\">`: (Tok, Tok) = \"Id\" \"Id\"; } -").unwrap(); - - compare(actual, expected); +") } #[test] fn test_macro_expansion_infer() { - let grammar = parser::parse_grammar(" + compare(" grammar Foo { token Tok where { }; Two = X X; Ids = Two<\"Id\">; } -").unwrap(); - - let actual = expand_macros(grammar).unwrap(); - let actual = infer_types(actual).unwrap(); - - let expected = parser::parse_grammar(" +"," grammar Foo { token Tok where { }; Ids: (Tok, Tok) = `Two<\"Id\">`; `Two<\"Id\">`: (Tok, Tok) = \"Id\" \"Id\"; } -").unwrap(); - - compare(actual, expected); +") +} + +#[test] +fn test_type_question() { + compare(" +grammar Foo { + token Tok where { }; + X = Y?; + Y = \"Hi\"; +} +"," +grammar Foo { + token Tok where { }; + X: std::option::Option = Y?; + Y: Tok = \"Hi\"; +} +") }