コード例 #1
0
ファイル: lexie_test.go プロジェクト: pschlump/lexie
func (s *LexieTestSuite) TestLexie(c *C) {

	return
	fmt.Fprintf(os.Stderr, "Test Parsing of REs, %s\n", tr.LF())

	dbOn["db_NFA"] = true
	dbOn["db_NFA_LnNo"] = true
	dbOn["db_DumpPool"] = true
	dbOn["parseExpression"] = true
	dbOn["CalcLength"] = true

	// Add a test for any issue
	c.Check(42, Equals, 42)
	// c.Assert("nope", Matches, "hel.*there")
	fmt.Printf("**** In Test Issues\n")
	//x := test7GenDFA()
	//c.Check(x, Equals, 0)

	n_err := 0
	n_skip := 0

	for ii, vv := range Lexie01Data {
		fmt.Printf("\n\n--- %d Test: %s -----------------------------------------------------------------------------\n\n", ii, vv.Test)

		Pool := nfa.NewNFA_Pool()
		Cur := Pool.GetNFA()
		Pool.InitState = Cur

		Pool.AddReInfo(vv.Re, "", 1, vv.Rv, nfa.InfoType{})
		Pool.Sigma = Pool.GenerateSigma()

		if false {
			DbPrintf("test7", "Pool=%s\n", tr.SVarI(Pool))
		}
		Pool.DumpPool(false)
		Pool.DumpPoolJSON(os.Stdout, vv.Re, vv.Rv)

		fmt.Printf("Sigma: ->%s<-\n", Pool.Sigma)

		newFile := fmt.Sprintf("./ref/nfa_%s.tst", vv.Test)
		cmpFile := fmt.Sprintf("./ref/nfa_%s.ref", vv.Test)
		gvFile := fmt.Sprintf("./ref/nfa_%s.gv", vv.Test)
		svgFile := fmt.Sprintf("./ref/nfa_%s.svg", vv.Test)
		fp, _ := Fopen(newFile, "w")
		Pool.DumpPoolJSON(fp, vv.Re, vv.Rv)
		fp.Close()
		newData, err := ioutil.ReadFile(newFile)
		if err != nil {
			panic("unable to read file, " + cmpFile)
		}

		if sizlib.Exists(cmpFile) {
			ref, err := ioutil.ReadFile(cmpFile)
			if err != nil {
				panic("unable to read file, " + cmpFile)
			}
			if string(ref) != string(newData) {
				c.Check(string(newData), Equals, string(ref))
				fmt.Printf("%sError%s: Test case %s failed to match\n", Red, Reset, vv.Test)
				n_err++
			}
		} else {
			n_skip++
		}

		gv, _ := Fopen(gvFile, "w")
		Pool.GenerateGVFile(gv, vv.Re, vv.Rv)
		gv.Close()

		out, err = exec.Command("/usr/local/bin/dot", "-Tsvg", "-o"+svgFile, gvFile).Output()
		if err != nil {
			fmt.Printf("Error from dot, %s, %s\n", err, tr.LF())
			fmt.Printf("Output: %s\n", out)
		}
	}
	if n_skip > 0 {
		fmt.Fprintf(os.Stderr, "%sSkipped, # of files without automated checks = %d%s\n", Yellow, n_skip, Reset)
		DbPrintf("debug", "\n\n%sSkipped, # of files without automated checks = %d%s\n", Yellow, n_skip, Reset)
	}
	if n_err > 0 {
		fmt.Fprintf(os.Stderr, "%sFailed, # of errors = %d%s\n", Red, n_err, Reset)
		DbPrintf("debug", "\n\n%sFailed, # of errors = %d%s\n", Red, n_err, Reset)
	} else {
		fmt.Fprintf(os.Stderr, "%sPASS%s\n", Green, Reset)
		DbPrintf("debug", "\n\n%sPASS%s\n", Green, Reset)
	}
}
コード例 #2
0
ファイル: lexie_test.go プロジェクト: pschlump/lexie
func (s *NFA_to_DFA_TestSuite) TestLexie(c *C) {

	return
	fmt.Fprintf(os.Stderr, "Test NFA to DFA, %s\n", tr.LF())

	n_err := 0
	n_skip := 0

	dbOn["db_DFAGen"] = true
	dbOn["db_DumpDFAPool"] = true
	dbOn["db_DFA_LnNo"] = true

	// -----------------------------------------------------------------------------------------------------------------
	// -----------------------------------------------------------------------------------------------------------------
	// -----------------------------------------------------------------------------------------------------------------
	// vv := Lexie01Data[11]
	for ii, vv := range Lexie01Data {
		if !vv.SkipTest {
			// {Test: "0011", Re: `a(bcd)*(ghi)+(jkl)*X`, Rv: 1011},     //
			Nfa := nfa.NewNFA_Pool()
			Cur := Nfa.GetNFA()
			Nfa.InitState = Cur

			c.Log("\n\n--- %d NFA to DFA Test: %s -----------------------------------------------------------------------------\n\n", ii, vv.Test)
			fmt.Printf("\n\n--- %d NFA to DFA Test: %s -----------------------------------------------------------------------------\n\n", ii, vv.Test)
			newFile := fmt.Sprintf("./ref/dfa_%s.tst", vv.Test)
			cmpFile := fmt.Sprintf("./ref/dfa_%s.ref", vv.Test)
			gvFile := fmt.Sprintf("./ref/dfa_%s.gv", vv.Test)
			svgFile := fmt.Sprintf("./ref/dfa_%s.svg", vv.Test)
			tabFile := fmt.Sprintf("./ref/dfa_%s.tab", vv.Test)
			Nfa.AddReInfo(vv.Re, "", 1, vv.Rv, nfa.InfoType{})
			// Nfa.Sigma = Nfa.GenerateSigma()
			Nfa.Sigma = Nfa.GenerateSigma()
			fmt.Printf("\nSigma: ->%s<-\n", Nfa.Sigma)
			fmt.Printf("\n\nRe: %s\n", vv.Re)
			Nfa.DumpPool(false)

			Dfa := dfa.NewDFA_Pool()
			Dfa.ConvNDA_to_DFA(Nfa)

			fp, _ := Fopen(newFile, "w")
			Dfa.DumpPoolJSON(fp, vv.Re, vv.Rv)
			fp.Close()
			newData, err := ioutil.ReadFile(newFile)
			if err != nil {
				panic("unable to read file, " + cmpFile)
			}

			if sizlib.Exists(cmpFile) {
				ref, err := ioutil.ReadFile(cmpFile)
				if err != nil {
					panic("unable to read file, " + cmpFile)
				}
				if string(ref) != string(newData) {
					c.Check(string(newData), Equals, string(ref))
					fmt.Printf("%sError%s: Test case %s failed to match\n", Red, Reset, vv.Test)
					n_err++
				}
			} else {
				n_skip++
			}
			// -----------------------------------------------------------------------------------------------------------------
			// Post dump
			// -----------------------------------------------------------------------------------------------------------------
			fmt.Printf("----------------------------------------------------------------------------------------------------\n")
			fmt.Printf("Bottom .. machine is...\n")
			fmt.Printf("----------------------------------------------------------------------------------------------------\n")
			Dfa.DumpPool(false)

			// func (dfa *NFA_PoolType) GenerateGVFile(fo io.Writer, td string, tn int) {
			gv, _ := Fopen(gvFile, "w")
			Dfa.GenerateGVFile(gv, vv.Re, vv.Rv)
			gv.Close()

			tf, _ := Fopen(tabFile, "w")
			//Dfa.DumpPoolJSON(fp, vv.Re, vv.Rv)
			Dfa.OutputInFormat(tf, "text") // text, go-code, c-code, json, xml etc.
			tf.Close()

			out, err = exec.Command("/usr/local/bin/dot", "-Tsvg", "-o"+svgFile, gvFile).Output()
			if err != nil {
				fmt.Printf("Error from dot, %s, %s\n", err, tr.LF())
				fmt.Printf("Output: %s\n", out)
			}
		}
	}
	// -----------------------------------------------------------------------------------------------------------------
	// -----------------------------------------------------------------------------------------------------------------
	// -----------------------------------------------------------------------------------------------------------------

	if n_err > 0 {
		fmt.Fprintf(os.Stderr, "%sFailed, # of errors = %d%s\n", Red, n_err, Reset)
		DbPrintf("debug", "\n\n%sFailed, # of errors = %d%s\n", Red, n_err, Reset)
	} else {
		fmt.Fprintf(os.Stderr, "%sPASS%s\n", Green, Reset)
		DbPrintf("debug", "\n\n%sPASS%s\n", Green, Reset)
	}
}