protected override void Execute(List <Ent> entities) { var parsers = new GenEntitasLangParser(_contexts); foreach (var ent in entities) { var str = ent.genEntitasLangInputString.Value; parsers.ParseWithComments(str); } var group_ = _contexts.main.GetGroup(MainMatcher.ParsedByGenEntitasLang); foreach (var ent in group_.GetEntities( )) { ProvideUniquePrefix(ent); } }
private void test_ParsesRoot( ) { Contexts contexts = null; before = () => { contexts = new Contexts(); }; new Each <String, Boolean> { { @" alias integer : ""int"" alias single : ""float"" alias double : ""double"" /*alias x : ""0"" alias y : ""1""*/ //alias z : ""2"" //comp Commented in First comp A in First unique publicFields : x : integer y : single comp B in Second publicFields : x : ""int"" y : ""double""" , false }, }.Do((given, throws) => { it["parses root"] = () => { var parsers = new GenEntitasLangParser(contexts); if (throws) { Action act = () => { parsers.ParseWithComments(given); }; act.Should( ).Throw <ParseException>( ); return; } parsers.ParseWithComments(given); contexts.main.hasAliasComp.should_be_true( ); var aliases = contexts.main.aliasComp.Values; aliases.Count.should_be(3); var ents = contexts.main.GetGroup(MainMatcher.Comp).GetEntities( ); ents.Length.should_be(2); { var ent = ents[0].isUniqueComp ? ents[0] : ents[1]; ent.hasComp.should_be_true( ); ent.comp.FullTypeName.should_be("A"); ent.comp.Name.should_be("A"); ent.hasContextNamesComp.should_be_true( ); ent.contextNamesComp.Values.should_contain("First"); ent.isUniqueComp.should_be_true( ); ent.hasPublicFieldsComp.should_be_true( ); ent.publicFieldsComp.Values.Count.should_be(2); ent.publicFieldsComp.Values[0].FieldName.should_be("x"); ent.publicFieldsComp.Values[0].TypeName.should_be("int"); ent.publicFieldsComp.Values[1].FieldName.should_be("y"); ent.publicFieldsComp.Values[1].TypeName.should_be("float"); } { var ent = ents[0].isUniqueComp ? ents[1] : ents[0]; ent.hasComp.should_be_true( ); ent.comp.FullTypeName.should_be("B"); ent.comp.Name.should_be("B"); ent.hasContextNamesComp.should_be_true( ); ent.contextNamesComp.Values.should_contain("Second"); ent.isUniqueComp.should_be_false( ); ent.hasPublicFieldsComp.should_be_true( ); ent.publicFieldsComp.Values.Count.should_be(2); ent.publicFieldsComp.Values[0].FieldName.should_be("x"); ent.publicFieldsComp.Values[0].TypeName.should_be("int"); ent.publicFieldsComp.Values[1].FieldName.should_be("y"); ent.publicFieldsComp.Values[1].TypeName.should_be("double"); } }; }); new Each <String, Boolean> { { @"// just to test comments. Test1 should be generated comp Test1 in Main // Test2 should not be generated /* comp Test2 in Main */ " , false }, }.Do((given, throws) => { it["parses root 2"] = () => { var parsers = new GenEntitasLangParser(contexts); if (throws) { Action act = () => { parsers.ParseWithComments(given); }; act.Should( ).Throw <ParseException>( ); return; } contexts.settings.SetGeneratedNamespace("Gen"); parsers.ParseWithComments(given); var ents = contexts.main.GetGroup(MainMatcher.Comp).GetEntities( ); ents.Length.should_be(1); { var ent = ents[0]; ent.hasComp.should_be_true( ); ent.comp.FullTypeName.should_be("Gen.Test1"); ent.comp.Name.should_be("Test1"); ent.hasContextNamesComp.should_be_true( ); ent.contextNamesComp.Values.should_contain("Main"); } }; }); }