processor/workers_charliteral_test.go GO 78 lines View on github.com → Search inside
1// SPDX-License-Identifier: MIT23package processor45import (6	"testing"7)89// 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 modelled11// as a string, so the embedded " opened a phantom string that swallowed the12// comment which followed. Languages where ' is unambiguously a char/rune literal13// (no ' digit separator, no lifetime/quote meaning) get a plain ' -> ' quote.14// C and C++ are deliberately excluded for now because ' is also a digit15// separator there (1'000'000) and needs disambiguation.1617func 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		"}")2627	CountStats(&fileJob)2829	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}3637func 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		"}")4748	CountStats(&fileJob)4950	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}5758func 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		"}")6869	CountStats(&fileJob)7071	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}

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.