From 048def765493eb5090f5480fa566ece2115f080f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 18 Jun 2015 06:34:19 -0400 Subject: [PATCH] rather than the hacky Debug impl, just only compare stuff that is more stable (and more imp't anyway) --- src/grammar/repr.rs | 20 +------------- src/normalize/lower/test.rs | 53 +++++++++++++++---------------------- 2 files changed, 22 insertions(+), 51 deletions(-) diff --git a/src/grammar/repr.rs b/src/grammar/repr.rs index ebb550c..8507354 100644 --- a/src/grammar/repr.rs +++ b/src/grammar/repr.rs @@ -4,7 +4,6 @@ * representation incrementally. */ -use std::cmp::Ord; use intern::InternedString; use grammar::parse_tree::Span; use std::collections::HashMap; @@ -48,7 +47,7 @@ pub enum TypeRepr { Lifetime(InternedString), } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Types { terminal_type: TypeRepr, nonterminal_types: HashMap @@ -77,23 +76,6 @@ impl Types { } } -#[derive(Debug)] -struct DummyTypes<'a> { - terminal_type: &'a TypeRepr, - nonterminal_types: Vec<(&'a InternedString, &'a TypeRepr)>, -} - -impl Debug for Types { - fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { - let mut nonterminal_types: Vec<_> = self.nonterminal_types.iter() - .collect(); - nonterminal_types.sort_by(|k1, k2| Ord::cmp(&k1.0, &k2.0)); - let dummy = DummyTypes { terminal_type: &self.terminal_type, - nonterminal_types: nonterminal_types }; - Debug::fmt(&dummy, fmt) - } -} - impl Display for TypeRepr { fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { match *self { diff --git a/src/normalize/lower/test.rs b/src/normalize/lower/test.rs index 43c3bd3..5764b91 100644 --- a/src/normalize/lower/test.rs +++ b/src/normalize/lower/test.rs @@ -16,37 +16,26 @@ grammar Foo { } ").unwrap(); let actual = normalize(grammar).unwrap(); - expect_debug(actual, - r#"Grammar { - action_fn_defns: [ - fn _(__0: Vec) -> Vec { (__0) }, - fn _(v: std::vec::Vec, e: std::option::Option) -> Vec { v.into_iter().chain(e.into_iter()).collect() }, - fn _(__0: Tok) -> std::option::Option { Some(__0) }, - fn _() -> std::option::Option { None }, - fn _() -> std::vec::Vec { vec![] }, - fn _(v: std::vec::Vec, e: Tok) -> std::vec::Vec { { let mut v = v; v.push(e); v } }, - fn _(__0: Tok, _: Tok) -> Tok { (__0) } - ], - productions: [ - Ids = Comma<"Id"> => ActionFn(0);, - Comma<"Id"> = (~"Id" ",")*, "Id"? => ActionFn(1);, - "Id"? = "Id" => ActionFn(2);, - "Id"? = => ActionFn(3);, - (~"Id" ",")* = => ActionFn(4);, - (~"Id" ",")* = (~"Id" ",")*, (~"Id" ",") => ActionFn(5);, - (~"Id" ",") = "Id", "," => ActionFn(6); - ], - conversions: {}, - types: DummyTypes { - terminal_type: Tok, - nonterminal_types: [ - ("\"Id\"?", std::option::Option), - ("(~\"Id\" \",\")", Tok), - ("(~\"Id\" \",\")*", std::vec::Vec), - ("Comma<\"Id\">", Vec), - ("Ids", Vec) - ] - } -}"#) + expect_debug(&actual.productions, + r#"[ + Ids = Comma<"Id"> => ActionFn(0);, + Comma<"Id"> = (~"Id" ",")*, "Id"? => ActionFn(1);, + "Id"? = "Id" => ActionFn(2);, + "Id"? = => ActionFn(3);, + (~"Id" ",")* = => ActionFn(4);, + (~"Id" ",")* = (~"Id" ",")*, (~"Id" ",") => ActionFn(5);, + (~"Id" ",") = "Id", "," => ActionFn(6); +]"#); + + expect_debug(&actual.action_fn_defns, + r#"[ + fn _(__0: Vec) -> Vec { (__0) }, + fn _(v: std::vec::Vec, e: std::option::Option) -> Vec { v.into_iter().chain(e.into_iter()).collect() }, + fn _(__0: Tok) -> std::option::Option { Some(__0) }, + fn _() -> std::option::Option { None }, + fn _() -> std::vec::Vec { vec![] }, + fn _(v: std::vec::Vec, e: Tok) -> std::vec::Vec { { let mut v = v; v.push(e); v } }, + fn _(__0: Tok, _: Tok) -> Tok { (__0) } +]"#); }