public void FlattenAst() { IMdlCompilerStage astFlattenerStage = new AstFlattenerCompilerStage(); astFlattenerStage.SetEnvironment(new Environment()); IAstNode astNode = new MdlParser(MdlParserTestFixture.CreateScanner( @"migration ""Waffle"" revision => 1: version 1: add table BlogPostApproval: BlogPostID nullable => true: reference ""FK0"" pk-table => BlogPost index unique => false constraint default => 1 ApprovedOn type => DateTime reference ""FK0"" pk-table => BlogPost index ""IXBAR"" unique => false alter table BlogPostApproval: remove reference ""FOO"" remove index ""Bar""")).Parse(); astNode.Accept(astFlattenerStage); IVersionNode version1Node = (IVersionNode)astNode.ChildNodes[0]; Assert.IsInstanceOfType(typeof(IAddReferenceNode), version1Node.ChildNodes[2]); Assert.IsInstanceOfType(typeof(IAddIndexNode), version1Node.ChildNodes[3]); Assert.IsInstanceOfType(typeof(IAddConstraintNode), version1Node.ChildNodes[4]); Assert.IsInstanceOfType(typeof(IAddReferenceNode), version1Node.ChildNodes[5]); Assert.IsInstanceOfType(typeof(IAddIndexNode), version1Node.ChildNodes[6]); }
public void ResolveShortcuts() { IAstNode astNode = new MdlParser(MdlParserTestFixture.CreateScanner(@"add table Foo: Bar type => Int32, references => Bar, unique => true, default => 2")).Parse(); IMdlCompilerStage shortcutResolutionStage = new ShortcutResolutionCompilerStage(); shortcutResolutionStage.SetEnvironment(new Environment()); astNode.Accept(shortcutResolutionStage); AssertAddTable(astNode, "Foo", null); Assert.IsInstanceOfType(typeof(IAddTableNode), astNode); Assert.IsInstanceOfType(typeof(IAddColumnNode), astNode.ChildNodes[0]); Assert.IsInstanceOfType(typeof(IAddReferenceNode), astNode.ChildNodes[0].ChildNodes[0]); Assert.IsInstanceOfType(typeof(IAddIndexNode), astNode.ChildNodes[0].ChildNodes[1]); Assert.IsInstanceOfType(typeof(IAddConstraintNode), astNode.ChildNodes[0].ChildNodes[2]); IAddReferenceNode addReferenceNode = (IAddReferenceNode)astNode.ChildNodes[0].ChildNodes[0]; Assert.AreEqual("Bar", AstNodePropertyUtil.AsString(addReferenceNode.Properties, "pk-table")); Assert.IsNotNull(addReferenceNode.Location); IAddIndexNode addIndexNode = (IAddIndexNode)astNode.ChildNodes[0].ChildNodes[1]; Assert.AreEqual("true", AstNodePropertyUtil.AsString(addIndexNode.Properties, "unique")); Assert.IsNotNull(addIndexNode.Location); IAddConstraintNode addConstraintNode = (IAddConstraintNode)astNode.ChildNodes[0].ChildNodes[2]; Assert.AreEqual(2, AstNodePropertyUtil.AsInteger(addConstraintNode.Properties, "default")); Assert.IsNotNull(addConstraintNode.Location); }
public void ParseNativeSqlNode() { IMdlParser mdlParser = new MdlParser(CreateScanner("execute native-sql upgrade-resource => UpdateWhateverHappensToBe")); IExecuteNativeSqlNode executeNativeSqlNode = (IExecuteNativeSqlNode)mdlParser.Parse(); Assert.AreEqual("UpdateWhateverHappensToBe", AstNodePropertyUtil.AsString(executeNativeSqlNode.Properties, "upgrade-resource")); }
public void ParseAddSchema2() { var parser = new MdlParser(CreateScanner("add schema \"Foo\"")); var addSchemaNode = (IAddSchemaNode)parser.Parse(); Assert.IsNotNull(addSchemaNode); Assert.AreEqual("Foo", addSchemaNode.Name); }
public void GenerateUpgrade() { IMdlParser mdlParser = new MdlParser(MdlParserTestFixture.CreateScanner(@"version 1: add table User: Login type => String, length => 200, nullable => false")); IAstNode astNode = mdlParser.Parse(); IMdlCompilerStage upgradeGenerationStage = new UpgradeGenerationStage(); astNode.Accept(upgradeGenerationStage); Assert.IsInstanceOfType(typeof(IUpgradeNode), astNode.ChildNodes[0]); Assert.AreEqual(1, astNode.ChildNodes[0].ChildNodes.Count); }
private void ParseMdlFileButton_Click(object sender, EventArgs e) { MdlParser parser = new MdlParser(MdlFilePathTextBox.Text); MDLFile file = parser.Parse(); // Graph graph = new Graph(file); // var verticesPaths = graph.VerticesCover(); VerticesCover verticesCover = new VerticesCover(new Graph(file)); OutPutTextBox.Text = "满足所有点覆盖情况下的最少路径\r\n" + string.Join("\r\n", verticesCover.VerticesCoverPaths()); // var edgesPaths = graph.EdgesCover(); EdgesCover edgesCover = new EdgesCover(new Graph(file)); OutPutTextBox.Text += "\r\n满足所有边覆盖情况下的所有路径\r\n" + string.Join("\r\n", edgesCover.EdgesCoverPaths()); }
public void ParsePropertyBlock() { IMdlParser mdlParser = new MdlParser(CreateScanner(@"environment development platform => sqlserver , host => ""(local)\sqlexpress"" database => Waffle integrated-authentication => true")); IEnvironmentNode environmentNode = (IEnvironmentNode)mdlParser.Parse(); Assert.AreEqual(new Location(0, 0), environmentNode.Location); Assert.AreEqual("sqlserver", AstNodePropertyUtil.AsString(environmentNode.Properties, "platform")); Assert.AreEqual("(local)\\sqlexpress", AstNodePropertyUtil.AsString(environmentNode.Properties, "host")); Assert.AreEqual("Waffle", AstNodePropertyUtil.AsString(environmentNode.Properties, "database")); Assert.AreEqual("true", AstNodePropertyUtil.AsString(environmentNode.Properties, "integrated-authentication")); }
public IDeploymentInfo ParseDeploymentInfo(StreamReader streamReader) { MdlScanner scanner = new MdlScanner(new SourceReader(streamReader)); scanner.RegisterKeyword("deployment"); scanner.RegisterKeyword("environment"); IMdlParser mdlParser = new MdlParser(scanner); IDeploymentNode deploymentNode = (IDeploymentNode)mdlParser.Parse(); EnvironmentCollection environments = new EnvironmentCollection(); foreach(IEnvironmentNode environmentNode in deploymentNode.ChildNodes) { environments.Add(ParseEnvironment(environmentNode)); } // foreach return new DeploymentInfo(environments); }
public void BuildSchemaInfo() { IMdlCompilerStage schemaInfoBuilderStage = new SchemaInfoBuilderCompilerStage(); schemaInfoBuilderStage.SetEnvironment(new Environment()); IAstNode astNode = new MdlParser(MdlParserTestFixture.CreateScanner( @"migration ""Waffle"" revision => 1: version 1: add table BlogPost: ID type => Int32, primary-key => true version 2: remove table BlogPost version 3: add table BlogPost: ID type => Int32, primary-key => true Version type => Int32 alter table BlogPost: add column PublishedOn type => DateTime add table BlogPostApproval: BlogPostID type => Int32: reference ""FK0"" pk-table => BlogPost ApprovedOn type => DateTime add reference FK1 fk-columns => [BlogPostID, ApprovedOn], pk-table => BlogPost, pk-column => Version add reference FK2 fk-table => BlogPostApproval, fk-columns => [ApprovedOn,BlogPostID], pk-table => BlogPost")).Parse(); astNode.Accept(schemaInfoBuilderStage); IAddTableNode addSchemaInfoTableNode = (IAddTableNode)astNode.ChildNodes[0].ChildNodes[0]; Assert.AreEqual("SchemaInfo", addSchemaInfoTableNode.Name); IAddColumnNode addVersionColumnNode = (IAddColumnNode)addSchemaInfoTableNode.ChildNodes[0]; Assert.AreEqual("Int64", AstNodePropertyUtil.AsString(addVersionColumnNode.Properties["type"].Value)); Assert.AreEqual("true", AstNodePropertyUtil.AsString(addVersionColumnNode.Properties["unique"].Value)); Assert.AreEqual("false", AstNodePropertyUtil.AsString(addVersionColumnNode.Properties["nullable"].Value)); }
private void GenerateStateDiagramButton_Click(object sender, EventArgs e) { MdlParser parser = new MdlParser(MdlFilePathTextBox.Text); MDLFile file = parser.Parse(); Graph graph = new Graph(file); SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "PlantUML file(*.wsd)|*.wsd"; if (dialog.ShowDialog() == DialogResult.OK) { File.WriteAllText(dialog.FileName, graph.ToPlantuml()); Process process = new Process(); process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = "cmd.exe"; process.StartInfo.Arguments = "/c plantuml " + dialog.FileName; process.Start(); process.WaitForExit(); PlantUML plantUML = new PlantUML(dialog.FileName.Replace(".wsd", ".png")); plantUML.Show(); } }
public void SubstituteTableTemplates() { IMdlCompilerStage templateSubstitutionStage = new TemplateSubstitutionCompilerStage(); templateSubstitutionStage.SetEnvironment(new Environment()); IAstNode astNode = new MdlParser(MdlParserTestFixture.CreateScanner( @"migration ""Waffle"" revision => 1: templates: table template T: ID type => Int32, nullable => false, ignore-primary-key => true, identity => true table template U: Foo type => String, length => 200 Abc type => String version 1: add table Foo: include-template T include-template U Baz type => Int32 add table Bar templates = [T, U]")).Parse(); astNode.Accept(templateSubstitutionStage); IVersionNode version1Node = (IVersionNode)astNode.ChildNodes[1]; AssertAddTable(version1Node.ChildNodes[0], "Foo", new ColumnDefinition("ID"), new ColumnDefinition("Foo"), new ColumnDefinition("Abc"), new ColumnDefinition("Baz")); AssertAddTable(version1Node.ChildNodes[1], "Bar", new ColumnDefinition("ID"), new ColumnDefinition("Foo"), new ColumnDefinition("Abc")); }
public void ResolvePrimaryKeys() { IMdlCompilerStage primaryKeyResolutionStage = new PrimaryKeyResolutionCompilerStage(); primaryKeyResolutionStage.SetEnvironment(new Environment()); IAstNode astNode = new MdlParser(MdlParserTestFixture.CreateScanner( @"migration ""Waffle"" revision => 1: defaults: default-primary-key ID type => Int32, nullable => false, ignore-primary-key => true, identity => true, default => ""foo"" version 1: add table Foo add table Bar: Ident primary-key => true")).Parse(); astNode.Accept(primaryKeyResolutionStage); IAstNode version1Node = astNode.ChildNodes[1]; IAstNode addTableFooNode = version1Node.ChildNodes[0]; IAstNode addTableBarNode = version1Node.ChildNodes[1]; IAddColumnNode addColumnNode = (IAddColumnNode)addTableFooNode.ChildNodes[0]; Assert.IsNotNull(addColumnNode); Assert.AreEqual(5, addColumnNode.Properties.Count); Assert.AreEqual("ID", addColumnNode.Name); Assert.AreEqual("Int32", AstNodePropertyUtil.AsString(addColumnNode.Properties, "type")); Assert.AreEqual("false", AstNodePropertyUtil.AsString(addColumnNode.Properties, "nullable")); Assert.AreEqual("true", AstNodePropertyUtil.AsString(addColumnNode.Properties, "primary-key")); Assert.AreEqual("true", AstNodePropertyUtil.AsString(addColumnNode.Properties, "identity")); Assert.AreEqual("foo", AstNodePropertyUtil.AsString(addColumnNode.Properties, "default")); addColumnNode = (IAddColumnNode)addTableBarNode.ChildNodes[0]; Assert.AreEqual("Ident", addColumnNode.Name); Assert.AreEqual("true", AstNodePropertyUtil.AsString(addColumnNode.Properties, "primary-key")); }
public void ParseAddConstraintNode() { MdlParser mdlParser = new MdlParser(CreateScanner(@"add constraint ""DF_Foo"" default => ""def""")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAddConstraintNode), astNode); IAddConstraintNode addConstraintNode = (IAddConstraintNode)astNode; Assert.AreEqual("def", AstNodePropertyUtil.AsString(addConstraintNode.Properties, "default")); }
public void ParseIncorrectBlockLayout() { IMdlParser mdlParser = new MdlParser(CreateScanner( @"add table Foo: ID index ""FK_User_Login_Whatever_Else""")); IAstNode astNode = mdlParser.Parse(); }
public void ParseRefactorNode() { IMdlParser mdlParser = new MdlParser(CreateScanner("refactor add-mirror-table table => Foo")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IRefactorNode), astNode); Assert.IsNull(astNode.Parent); Assert.AreEqual(1, astNode.Properties.Count); IRefactorNode refactorNode = (IRefactorNode)astNode; Assert.AreEqual("add-mirror-table", refactorNode.Name); }
public void ParseAlterColumnNode() { IMdlParser mdlParser = new MdlParser(CreateScanner(@"alter column Login nullable => false")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAlterColumnNode), astNode); IAlterColumnNode alterColumnNode = (IAlterColumnNode)astNode; Assert.AreEqual("Login", alterColumnNode.Name); Assert.AreEqual("false", AstNodePropertyUtil.AsString(alterColumnNode.Properties, "nullable")); }
public void ParseMigrationNodeTree() { IMdlParser mdlParser = new MdlParser(CreateScanner( @"migration ""Waffle"" revision => 1, configuration => Debug: baseline version 1 description => ""Updating database for the first time ever"": add table User: Login type => String, length => 200 add column Password type => Binary, length => 64 version 2 description => ""Updating the second time""")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IMigrationNode), astNode); Assert.IsNull(astNode.Parent); Assert.AreEqual(3, astNode.ChildNodes.Count); IMigrationNode migrationNode = (IMigrationNode)astNode; Assert.AreEqual("Waffle", migrationNode.Name); Assert.AreEqual(1, AstNodePropertyUtil.AsInteger(migrationNode.Properties, "revision")); Assert.AreEqual("Debug", AstNodePropertyUtil.AsString(migrationNode.Properties, "configuration")); Assert.IsInstanceOfType(typeof(IBaselineNode), astNode.ChildNodes[0]); Assert.IsInstanceOfType(typeof(IVersionNode), astNode.ChildNodes[1]); Assert.IsInstanceOfType(typeof(IAddTableNode), astNode.ChildNodes[1].ChildNodes[0]); Assert.IsInstanceOfType(typeof(IVersionNode), astNode.ChildNodes[2]); }
public void ParseComplexFile() { using(Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("octalforty.Wizardby.Tests.Resources.Waffle.mdl")) { IMdlParser mdlParser = new MdlParser(CreateScanner(new StreamReader(resourceStream, Encoding.UTF8))); IAstNode astNode = mdlParser.Parse(); } // using }
private Schema GetSchema() { Environment environment = new Environment(); using (Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("octalforty.Wizardby.Tests.Resources.Blog.mdl")) { IMdlParser mdlParser = new MdlParser(MdlParserTestFixture.CreateScanner( new StreamReader(resourceStream, Encoding.UTF8))); IMdlCompiler mdlCompiler = new MdlCompiler(new NullCodeGenerator(), environment); mdlCompiler.Compile(mdlParser.Parse(), MdlCompilationOptions.All); } // using return environment.Schema; }
public void ParseAddColumnNodeTree() { IMdlParser mdlParser = new MdlParser(CreateScanner(@"add column Login: constraint ""DF_Foo"" default => ""foo""")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAddColumnNode), astNode); IAddColumnNode addColumnNode = (IAddColumnNode)astNode; Assert.AreEqual("Login", addColumnNode.Name); Assert.IsInstanceOfType(typeof(IAddConstraintNode), astNode.ChildNodes[0]); IAddConstraintNode addConstraintNode = (IAddConstraintNode)astNode.ChildNodes[0]; Assert.AreEqual("DF_Foo", addConstraintNode.Name); Assert.AreEqual("foo", AstNodePropertyUtil.AsString(addConstraintNode.Properties, "default")); }
public void ParseRemoveConstraintNode() { MdlParser mdlParser = new MdlParser(CreateScanner(@"remove constraint DF_Foo")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IRemoveConstraintNode), astNode); IRemoveConstraintNode removeConstraintNode = (IRemoveConstraintNode)astNode; Assert.AreEqual("DF_Foo", removeConstraintNode.Name); }
public void ParseAnonymousAddReferenceNode() { IMdlParser mdlParser = new MdlParser(CreateScanner( @"add column Login type => String, length => 200: add reference")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAddColumnNode), astNode); Assert.IsInstanceOfType(typeof(IAddReferenceNode), astNode.ChildNodes[0]); IAddReferenceNode addReferenceNode = (IAddReferenceNode)astNode.ChildNodes[0]; Assert.IsEmpty(addReferenceNode.Name); }
public void ParseImplicitAddIndexNode() { IMdlParser mdlParser = new MdlParser(CreateScanner( @"add column Login type => String, length => 200: index ""UQ_Login""unique => true")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAddColumnNode), astNode); Assert.IsInstanceOfType(typeof(IAddIndexNode), astNode.ChildNodes[0]); IAddIndexNode addIndexNode = (IAddIndexNode)astNode.ChildNodes[0]; Assert.AreEqual("UQ_Login", addIndexNode.Name); Assert.AreEqual("true", AstNodePropertyUtil.AsString(addIndexNode.Properties, "unique")); }
public void ParseAddIndexNode2() { IMdlParser mdlParser = new MdlParser(CreateScanner(@"add index ""UQ_Login"" columns => [[Login, desc], ID]")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAddIndexNode), astNode); Assert.IsInstanceOfType(typeof(IListAstNodePropertyValue), astNode.Properties["columns"].Value); IListAstNodePropertyValue columnsList = (IListAstNodePropertyValue)astNode.Properties["columns"].Value; Assert.IsInstanceOfType(typeof(IListAstNodePropertyValue), columnsList); Assert.IsInstanceOfType(typeof(IListAstNodePropertyValue), columnsList.Items[0]); IListAstNodePropertyValue loginList = (IListAstNodePropertyValue)columnsList.Items[0]; Assert.AreEqual("Login", ((IStringAstNodePropertyValue)loginList.Items[0]).Value); Assert.AreEqual("desc", ((IStringAstNodePropertyValue)loginList.Items[1]).Value); Assert.AreEqual("ID", ((IStringAstNodePropertyValue)columnsList.Items[1]).Value); }
public void ParseAnonymousAddIndexNode() { IMdlParser mdlParser = new MdlParser(CreateScanner(@"add column Foo: add index unique => true")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAddColumnNode), astNode); Assert.IsInstanceOfType(typeof(IAddIndexNode), astNode.ChildNodes[0]); IAddIndexNode addIndexNode = (IAddIndexNode)astNode.ChildNodes[0]; Assert.IsEmpty(addIndexNode.Name); Assert.AreEqual("true", AstNodePropertyUtil.AsString(addIndexNode.Properties, "unique")); }
public void ParseAddIndexNode3() { IMdlParser mdlParser = new MdlParser(CreateScanner(@"add index ""IX_Login"" table => User, column => Login")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAddIndexNode), astNode); Assert.AreEqual("IX_Login", ((IAddIndexNode)astNode).Name); Assert.AreEqual("User", AstNodePropertyUtil.AsString(astNode.Properties["table"].Value)); Assert.AreEqual("Login", AstNodePropertyUtil.AsString(astNode.Properties["column"].Value)); }
public void ConstructorThrowsArgumentNullExceptionOnNullScanner() { IMdlParser mdlParser = new MdlParser(null); }
public void ParseAddReferenceNode2() { IMdlParser mdlParser = new MdlParser(CreateScanner( @"add table Foo: add reference ""FK_User_Login_Whatever_Else""")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAddTableNode), astNode); Assert.IsInstanceOfType(typeof(IAddReferenceNode), astNode.ChildNodes[0]); IAddReferenceNode addReferenceNode = (IAddReferenceNode)astNode.ChildNodes[0]; Assert.AreEqual("FK_User_Login_Whatever_Else", addReferenceNode.Name); }
public void ParseRemoveReferenceNode() { IMdlParser mdlParser = new MdlParser(CreateScanner(@"remove reference ""FK_User_Login_Whatever_Else"" fk-table => User")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IRemoveReferenceNode), astNode); IRemoveReferenceNode removeReferenceNode = (IRemoveReferenceNode)astNode; Assert.AreEqual("FK_User_Login_Whatever_Else", removeReferenceNode.Name); Assert.AreEqual("User", AstNodePropertyUtil.AsString(removeReferenceNode.Properties, "fk-table")); }
public void ParseRemoveIndexNode() { IMdlParser mdlParser = new MdlParser(CreateScanner(@"remove index ""IX_User_Login"" table-name => User")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IRemoveIndexNode), astNode); IRemoveIndexNode removeIndexNode = (IRemoveIndexNode)astNode; Assert.AreEqual(new Location(0, 0), removeIndexNode.Location); Assert.AreEqual("IX_User_Login", removeIndexNode.Name); Assert.AreEqual("User", AstNodePropertyUtil.AsString(removeIndexNode.Properties, "table-name")); }
public void ParseAddReferenceNode() { IMdlParser mdlParser = new MdlParser(CreateScanner( @"add column Login type => String, length => 200: add reference ""FK_User_Login_Whatever_Else""")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAddColumnNode), astNode); Assert.IsInstanceOfType(typeof(IAddReferenceNode), astNode.ChildNodes[0]); IAddReferenceNode addReferenceNode = (IAddReferenceNode)astNode.ChildNodes[0]; Assert.AreEqual("FK_User_Login_Whatever_Else", addReferenceNode.Name); }
public void ParseAddIndexNode() { IMdlParser mdlParser = new MdlParser(CreateScanner(@"add index ""UQ_Login"" columns => [Login, ID]")); IAstNode astNode = mdlParser.Parse(); Assert.IsInstanceOfType(typeof(IAddIndexNode), astNode); Assert.AreEqual("UQ_Login", ((IAddIndexNode)astNode).Name); Assert.IsInstanceOfType(typeof(IListAstNodePropertyValue), astNode.Properties["columns"].Value); }