Parser tests now show exact line and column where data is mismatched
This commit is contained in:
		
							parent
							
								
									e069569c3c
								
							
						
					
					
						commit
						6a5851c9eb
					
				| @ -5,8 +5,9 @@ import "testing" | ||||
| // import "git.tebibyte.media/sashakoshka/arf/types" | ||||
| 
 | ||||
| func checkTree (modulePath string, correct string, test *testing.T) { | ||||
| 	tree, err := Parse(modulePath) | ||||
| 	tree, err  := Parse(modulePath) | ||||
| 	treeString := tree.ToString(0) | ||||
| 	treeRunes  := []rune(treeString) | ||||
| 	 | ||||
| 	test.Log("CORRECT TREE:") | ||||
| 	test.Log(correct) | ||||
| @ -20,11 +21,46 @@ func checkTree (modulePath string, correct string, test *testing.T) { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	if treeString != correct { | ||||
| 		test.Log("trees not equal!") | ||||
| 	equal  := true | ||||
| 	line   := 0 | ||||
| 	column := 0 | ||||
| 
 | ||||
| 	for index, correctChar := range correct { | ||||
| 		if index >= len(treeRunes) {			 | ||||
| 			test.Log ( | ||||
| 				"parsed is too short at line", line + 1, | ||||
| 				"col", column + 1) | ||||
| 			test.Fail() | ||||
| 			return | ||||
| 		} | ||||
| 		 | ||||
| 		if correctChar != treeRunes[index] {		 | ||||
| 			test.Log ( | ||||
| 				"trees not equal at line", line + 1, | ||||
| 				"col", column + 1) | ||||
| 			test.Log("correct: [" + string(correctChar) + "]") | ||||
| 			test.Log("got:     [" + string(treeRunes[index]) + "]") | ||||
| 			test.Fail() | ||||
| 			return | ||||
| 		} | ||||
| 
 | ||||
| 		if correctChar == '\n' { | ||||
| 			line ++ | ||||
| 			column = 0 | ||||
| 		} else { | ||||
| 			column ++ | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	if len(treeString) > len(correct) { | ||||
| 		test.Log("parsed is too long") | ||||
| 		test.Fail() | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	if !equal { | ||||
| 		return | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestMeta (test *testing.T) { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user