cleanup tests a little

This commit is contained in:
Niko Matsakis 2015-06-16 11:34:01 -04:00
parent 7219b9c2d6
commit 975ae0a200
2 changed files with 39 additions and 45 deletions

View File

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

View File

@ -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 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 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<Tok> = Y?;
Y: Tok = \"Hi\";
}
")
}