/* * Public Domain Software * * I (Matthias Ladkau) am the author of the source code in this file. * I have placed the source code in this file in the public domain. * * For further information see: http://creativecommons.org/publicdomain/zero/1.0/ */ package parser import ( "flag" "fmt" "os" "testing" ) // Main function for all tests in this package func TestMain(m *testing.M) { flag.Parse() res := m.Run() // Check if all nodes have been tested for _, n := range astNodeMap { if _, ok := usedNodes[n.Name]; !ok { fmt.Println("Not tested node: ", n.Name) } } os.Exit(res) } // Used nodes map which is filled during unit testing. Prefilled with tokens which // will not be generated by the parser // var usedNodes = map[string]bool{ NodeEOF: true, // Only used as end term "": true, // No node e.g. semicolon - These nodes should never be part of an AST } func UnitTestParse(name string, input string) (*ASTNode, error) { n, err := ParseWithRuntime(name, input, &DummyRuntimeProvider{}) return n, err } // Helper objects type DummyRuntimeProvider struct { } func (d *DummyRuntimeProvider) Runtime(n *ASTNode) Runtime { // Make the encountered node as used usedNodes[n.Name] = true return nil }