|
| 1 | +package utils |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestEvaluate(t *testing.T) { |
| 6 | + items := []struct { |
| 7 | + str string |
| 8 | + expected string |
| 9 | + }{ |
| 10 | + {str: "test\\ntest", expected: "test\ntest"}, |
| 11 | + {str: "test\ntest", expected: "test\ntest"}, |
| 12 | + {str: "test\\\\ntest", expected: "test\\ntest"}, |
| 13 | + {str: "\\n", expected: "\n"}, |
| 14 | + {str: "\\\\n\\n", expected: "\\n\n"}, |
| 15 | + {str: "\\n", expected: "\n"}, |
| 16 | + {str: "\n", expected: "\n"}, |
| 17 | + {str: "\\n\\thi", expected: "\n\thi"}, |
| 18 | + {str: "\\n\t\\n\\t\n\n", expected: "\n\t\n\t\n\n"}, |
| 19 | + {str: "\\\\n\\\\thallo\\\\t\\\\n", expected: "\\n\\thallo\\t\\n"}, |
| 20 | + } |
| 21 | + for _, item := range items { |
| 22 | + t.Run(item.str, func(t *testing.T) { |
| 23 | + eval := Evaluate(item.str) |
| 24 | + if eval != item.expected { |
| 25 | + t.Fatalf("str '%s' should be evaluated to '%s' but was '%s'.", item.str, item.expected, eval) |
| 26 | + } |
| 27 | + }) |
| 28 | + } |
| 29 | +} |
0 commit comments