1// SPDX-License-Identifier: MIT23package processor45import "testing"67// https://github.com/boyter/scc/issues/728// Turns out the above is due to BOM being present for that file9func TestCountStatsIssue72(t *testing.T) {10 ProcessConstants()11 fileJob := FileJob{12 Language: "C#",13 }1415 fileJob.SetContent(` // Comment 116namespace Baz17{18 using System;1920 public class FooClass21 {22 public void Test(string report)23 {24 // Comment 225 throw new NotImplementedException();26 }27 }28}`)2930 // Set the BOM31 fileJob.Content[0] = 23932 fileJob.Content[1] = 18733 fileJob.Content[2] = 1913435 CountStats(&fileJob)3637 if fileJob.Lines != 14 {38 t.Errorf("Expected 14 lines got %d", fileJob.Lines)39 }4041 if fileJob.Code != 11 {42 t.Errorf("Expected 11 lines got %d", fileJob.Code)43 }4445 if fileJob.Comment != 2 {46 t.Errorf("Expected 2 lines got %d", fileJob.Comment)47 }4849 if fileJob.Blank != 1 {50 t.Errorf("Expected 1 lines got %d", fileJob.Blank)51 }52}5354func TestCountStatsPr76(t *testing.T) {55 ProcessConstants()56 fileJob := FileJob{57 Language: "Go",58 }5960 fileJob.SetContent(`package main61var MyString = ` + "`\\`" + `62// Comment`)6364 CountStats(&fileJob)6566 if fileJob.Lines != 3 {67 t.Errorf("Expected 3 lines")68 }6970 if fileJob.Code != 2 {71 t.Errorf("Expected 2 lines got %d", fileJob.Code)72 }7374 if fileJob.Comment != 1 {75 t.Errorf("Expected 1 lines got %d", fileJob.Comment)76 }7778 if fileJob.Blank != 0 {79 t.Errorf("Expected 0 lines got %d", fileJob.Blank)80 }81}8283// https://github.com/boyter/scc/issues/6284func TestCountStatsIssue62(t *testing.T) {85 ProcessConstants()86 fileJob := FileJob{87 Language: "Python",88 }8990 fileJob.SetContent(`def f():91 """92 This is a docstring93 """94 # A normal comment9596 hello_world = "Some string declaration"97 print(hello_world)98 pass99100 def g():101 '''102 This is a not PEP-8 conform docstring'''103 pass104`)105106 CountStats(&fileJob)107108 if fileJob.Lines != 14 {109 t.Errorf("Expected 14 lines got %d", fileJob.Lines)110 }111112 if fileJob.Code != 6 {113 t.Errorf("Expected 6 lines got %d", fileJob.Code)114 }115116 if fileJob.Comment != 6 {117 t.Errorf("Expected 6 lines got %d", fileJob.Comment)118 }119120 if fileJob.Blank != 2 {121 t.Errorf("Expected 2 lines got %d", fileJob.Blank)122 }123}124125func TestCountStatsIssue123(t *testing.T) {126 ProcessConstants()127 fileJob := FileJob{128 Language: "Python",129 }130131 fileJob.SetContent(`"""132hello there! how's it going?133"""`)134135 CountStats(&fileJob)136137 if fileJob.Lines != 3 {138 t.Errorf("Expected 3 lines got %d", fileJob.Lines)139 }140141 if fileJob.Code != 0 {142 t.Errorf("Expected 0 lines got %d", fileJob.Code)143 }144145 if fileJob.Comment != 3 {146 t.Errorf("Expected 3 lines got %d", fileJob.Comment)147 }148149 if fileJob.Blank != 0 {150 t.Errorf("Expected 0 lines got %d", fileJob.Blank)151 }152}153154func TestCountStatsIssue246(t *testing.T) {155 ProcessConstants()156 fileJob := FileJob{157 Language: "Python",158 }159160 // Apostrophes inside triple-double-quoted docstrings should not161 // break docstring parsing (issue #246).162 fileJob.SetContent(`#!/usr/bin/env python3163164"""165Docstrings containing an apostrophe (') are handled incorrectly166"""167# A comment168if __name__ == '__main__':169 print('Hello, World!')170`)171172 CountStats(&fileJob)173174 if fileJob.Lines != 8 {175 t.Errorf("Expected 8 lines got %d", fileJob.Lines)176 }177178 if fileJob.Code != 2 {179 t.Errorf("Expected 2 code lines got %d", fileJob.Code)180 }181182 if fileJob.Comment != 5 {183 t.Errorf("Expected 5 comment lines got %d", fileJob.Comment)184 }185186 if fileJob.Blank != 1 {187 t.Errorf("Expected 1 blank line got %d", fileJob.Blank)188 }189}190191func TestCountStatsIssue230(t *testing.T) {192 ProcessConstants()193 fileJob := FileJob{194 Language: "Elm",195 }196197 fileJob.SetContent(`module Main exposing (main)198199import Html200201202main =203 Html.node "style" [] [ Html.text "div[role=button] {-webkit-tap-highlight-color: transparent}" ]204205206a =207 3`)208209 CountStats(&fileJob)210211 if fileJob.Lines != 11 {212 t.Errorf("Expected 11 lines got %d", fileJob.Lines)213 }214215 if fileJob.Code != 6 {216 t.Errorf("Expected 6 lines got %d", fileJob.Code)217 }218219 if fileJob.Comment != 0 {220 t.Errorf("Expected 0 lines got %d", fileJob.Comment)221 }222223 if fileJob.Blank != 5 {224 t.Errorf("Expected 5 lines got %d", fileJob.Blank)225 }226}227228func TestCountStatsComplexityLines(t *testing.T) {229 ProcessConstants()230 fileJob := FileJob{231 Language: "Go",232 }233234 fileJob.SetContent(`fileJob.Comment++235 if fileJob.Callback != nil {236 if !fileJob.Callback.ProcessLine(fileJob, fileJob.Lines, LINE_COMMENT) {237 return238 }239 }240 if Trace {241 printTrace(fmt.Sprintf("%s line %d ended with state: %d: counted as comment", fileJob.Location, fileJob.Lines, currentState))242 }`)243244 CountStats(&fileJob)245246 if len(fileJob.ComplexityLine) != int(fileJob.Lines) {247 t.Errorf("Expected %d lines got %d", fileJob.Lines, len(fileJob.ComplexityLine))248 }249}
Findings
✓ No findings reported for this file.