|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | + |
| 3 | +package processor |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +// Follow-up to https://github.com/boyter/scc/issues/175 (dwmcrobb's comment): |
| 10 | +// a character/rune literal containing a double quote, e.g. '"', was not modelled |
| 11 | +// as a string, so the embedded " opened a phantom string that swallowed the |
| 12 | +// comment which followed. Languages where ' is unambiguously a char/rune literal |
| 13 | +// (no ' digit separator, no lifetime/quote meaning) get a plain ' -> ' quote. |
| 14 | +// C and C++ are deliberately excluded for now because ' is also a digit |
| 15 | +// separator there (1'000'000) and needs disambiguation. |
| 16 | + |
| 17 | +func TestCountStatsCharLiteralGo(t *testing.T) { |
| 18 | + ProcessConstants() |
| 19 | + fileJob := FileJob{Language: "Go"} |
| 20 | + fileJob.SetContent("package main\n" + |
| 21 | + "func main() {\n" + |
| 22 | + "\tc := '\"'\n" + |
| 23 | + "\t/* block\n" + |
| 24 | + "\t comment */\n" + |
| 25 | + "}") |
| 26 | + |
| 27 | + CountStats(&fileJob) |
| 28 | + |
| 29 | + if fileJob.Code != 4 { |
| 30 | + t.Errorf("Expected 4 code got %d", fileJob.Code) |
| 31 | + } |
| 32 | + if fileJob.Comment != 2 { |
| 33 | + t.Errorf("Expected 2 comments got %d", fileJob.Comment) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +func TestCountStatsCharLiteralJava(t *testing.T) { |
| 38 | + ProcessConstants() |
| 39 | + fileJob := FileJob{Language: "Java"} |
| 40 | + fileJob.SetContent("class T {\n" + |
| 41 | + " void m() {\n" + |
| 42 | + " char c = '\"';\n" + |
| 43 | + " /* block\n" + |
| 44 | + " comment */\n" + |
| 45 | + " }\n" + |
| 46 | + "}") |
| 47 | + |
| 48 | + CountStats(&fileJob) |
| 49 | + |
| 50 | + if fileJob.Code != 5 { |
| 51 | + t.Errorf("Expected 5 code got %d", fileJob.Code) |
| 52 | + } |
| 53 | + if fileJob.Comment != 2 { |
| 54 | + t.Errorf("Expected 2 comments got %d", fileJob.Comment) |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +func TestCountStatsCharLiteralCSharp(t *testing.T) { |
| 59 | + ProcessConstants() |
| 60 | + fileJob := FileJob{Language: "C#"} |
| 61 | + fileJob.SetContent("class T {\n" + |
| 62 | + " void M() {\n" + |
| 63 | + " char c = '\"';\n" + |
| 64 | + " /* block\n" + |
| 65 | + " comment */\n" + |
| 66 | + " }\n" + |
| 67 | + "}") |
| 68 | + |
| 69 | + CountStats(&fileJob) |
| 70 | + |
| 71 | + if fileJob.Code != 5 { |
| 72 | + t.Errorf("Expected 5 code got %d", fileJob.Code) |
| 73 | + } |
| 74 | + if fileJob.Comment != 2 { |
| 75 | + t.Errorf("Expected 2 comments got %d", fileJob.Comment) |
| 76 | + } |
| 77 | +} |
0 commit comments