feat: enhance awk,c,cpp complexity checks (#506) · boyter/scc@657f5fe

6 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -18,7 +18,7 @@

1818

<th>456</th>

1919

<th>7599</th>

2020

<th>1516</th>

21-

<th>253987</th>

21+

<th>254099</th>

2222

<th>4050</th>

2323

</tr><tr>

2424

<td>processor/formatters.go</td>

@@ -250,16 +250,6 @@

250250

<td>0</td>

251251

<td>2209</td>

252252

<td>35</td>

253-

</tr><tr>

254-

<td>processor/cocomo_test.go</td>

255-

<td></td>

256-

<td>37</td>

257-

<td>8</td>

258-

<td>4</td>

259-

<td>25</td>

260-

<td>6</td>

261-

<td>686</td>

262-

<td>23</td>

263253

</tr><tr>

264254

<td>processor/bloom.go</td>

265255

<td></td>

@@ -270,6 +260,16 @@

270260

<td>2</td>

271261

<td>1062</td>

272262

<td>29</td>

263+

</tr><tr>

264+

<td>processor/cocomo_test.go</td>

265+

<td></td>

266+

<td>37</td>

267+

<td>8</td>

268+

<td>4</td>

269+

<td>25</td>

270+

<td>6</td>

271+

<td>686</td>

272+

<td>23</td>

273273

</tr><tr>

274274

<td>processor/helpers_test.go</td>

275275

<td></td>

@@ -318,7 +318,7 @@

318318

<td>0</td>

319319

<td>4</td>

320320

<td>0</td>

321-

<td>22805</td>

321+

<td>22917</td>

322322

<td>5</td>

323323

</tr></tbody>

324324

<tfoot><tr>

@@ -329,7 +329,7 @@

329329

<th>456</th>

330330

<th>7599</th>

331331

<th>1516</th>

332-

<th>253987</th>

332+

<th>254099</th>

333333

<th>4050</th>

334334

</tr>

335335

<tr>

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,25 @@

1+

// 4 Complexity

2+

#include <iostream>

3+
4+

int main()

5+

{

6+

int i = 0;

7+

while(1) {

8+

std::cin >> i;

9+

if(i == 0) {

10+

return 0;

11+

}

12+

switch(i) {

13+

case 1:

14+

std::cout << "one\n";

15+

break;

16+

case 2:

17+

std::cout << "two\n";

18+

break;

19+

case 3:

20+

std::cout << "three\n";

21+

default:

22+

std::cout << "try again\n";

23+

}

24+

}

25+

}

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,28 @@

1+

#!/usr/bin/nawk -f

2+
3+

BEGIN {

4+

print("Enter string to encode:")

5+

}

6+
7+

{

8+

print("Encoded string:")

9+

print(rot13($0))

10+

}

11+
12+

function rot13(str, new, idx) {

13+

new = ""

14+

for (idx = 1; idx <= length; ++idx) {

15+

new = new rot13_impl(substr(str, idx, 1))

16+

}

17+

return new

18+

}

19+
20+

function rot13_impl(ch, list, idx) {

21+

list = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"

22+

idx = index(list, ch)

23+

if (idx == 0) {

24+

return ch

25+

} else {

26+

return substr(list, idx + 13, 1)

27+

}

28+

}

Original file line numberDiff line numberDiff line change

@@ -514,7 +514,21 @@

514514

"quotes": []

515515

},

516516

"AWK": {

517-

"complexitychecks": [],

517+

"complexitychecks": [

518+

"else ",

519+

"for ",

520+

"for(",

521+

"if ",

522+

"if(",

523+

"switch ",

524+

"switch(",

525+

"while ",

526+

"while(",

527+

"|| ",

528+

"&& ",

529+

"!= ",

530+

"== "

531+

],

518532

"extensions": [

519533

"awk"

520534

],

@@ -531,7 +545,8 @@

531545

"shebangs": [

532546

"awk",

533547

"gawk",

534-

"mawk"

548+

"mawk",

549+

"nawk"

535550

]

536551

},

537552

"bait": {

@@ -953,7 +968,9 @@

953968

"if ",

954969

"if(",

955970

"switch ",

971+

"switch(",

956972

"while ",

973+

"while(",

957974

"else ",

958975

"|| ",

959976

"&& ",

@@ -988,7 +1005,9 @@

9881005

"if ",

9891006

"if(",

9901007

"switch ",

1008+

"switch(",

9911009

"while ",

1010+

"while(",

9921011

"else ",

9931012

"|| ",

9941013

"&& ",

@@ -1090,7 +1109,9 @@

10901109

"if ",

10911110

"if(",

10921111

"switch ",

1112+

"switch(",

10931113

"while ",

1114+

"while(",

10941115

"else ",

10951116

"|| ",

10961117

"&& ",

@@ -1128,7 +1149,9 @@

11281149

"if ",

11291150

"if(",

11301151

"switch ",

1152+

"switch(",

11311153

"while ",

1154+

"while(",

11321155

"else ",

11331156

"|| ",

11341157

"&& ",

Original file line numberDiff line numberDiff line change

@@ -915,9 +915,82 @@ else

915915

fi

916916
917917

# Try out specific languages

918-

for i in 'Bosque ' 'Flow9 ' 'Bitbucket Pipeline ' 'Docker ignore ' 'Q# ' 'Futhark ' 'Alloy ' 'Wren ' 'Monkey C ' 'Alchemist ' 'Luna ' 'ignore ' 'XML Schema ' 'Web Services' 'Go ' 'Java ' 'Boo ' 'License ' 'BASH ' 'C Shell ' 'Korn Shell ' 'Makefile ' 'Shell ' 'Zsh ' 'Rakefile ' 'Gemfile ' 'Dockerfile ' 'Yarn ' 'Sieve ' 'F# ' 'Elm ' 'Terraform ' 'Clojure ' 'C# ' 'LLVM IR ' 'HAML ' 'FXML ' 'DM ' 'Nushell ' 'R ' 'Racket ' 'DOT ' 'YAML ' 'Teal ' 'FSL ' 'INI ' 'Hare ' 'Templ ' 'Cuda ' 'GraphQL ' 'Bicep ' 'Pkl ' 'TypeSpec ' 'LALRPOP ' 'Snakemake ' 'OpenQASM ' 'Typst ' 'ZoKrates ' 'Chapel ' 'Slang ' 'Circom ' 'Proto ' 'wenyan ' 'Cangjie ' 'Clipper ' 'Slint '

918+

specificLanguages=(

919+

'Alchemist '

920+

'Alloy '

921+

'Arturo '

922+

'AWK '

923+

'BASH '

924+

'Bicep '

925+

'Bitbucket Pipeline '

926+

'Boo '

927+

'Bosque '

928+

'C Shell '

929+

'C# '

930+

'Cairo '

931+

'Cangjie '

932+

'Chapel '

933+

'Circom '

934+

'Clipper '

935+

'Clojure '

936+

'Cuda '

937+

'DM '

938+

'Docker ignore '

939+

'Dockerfile '

940+

'DOT '

941+

'Elm '

942+

'F# '

943+

'Factor '

944+

'Flow9 '

945+

'FSL '

946+

'Futhark '

947+

'FXML '

948+

'Gemfile '

949+

'Go '

950+

'GraphQL '

951+

'HAML '

952+

'Hare '

953+

'ignore '

954+

'INI '

955+

'Java '

956+

'JSONC '

957+

'Korn Shell '

958+

'LALRPOP '

959+

'License '

960+

'LLVM IR '

961+

'Luna '

962+

'Makefile '

963+

'Monkey C '

964+

'Nushell '

965+

'OpenQASM '

966+

'Pkl '

967+

'Proto '

968+

'Q# '

969+

'R '

970+

'Racket '

971+

'Rakefile '

972+

'Shell '

973+

'Sieve '

974+

'Slang '

975+

'Slint '

976+

'Snakemake '

977+

'Teal '

978+

'Templ '

979+

'Terraform '

980+

'TypeSpec '

981+

'Typst '

982+

'Web Services '

983+

'wenyan '

984+

'Wren '

985+

'XML Schema '

986+

'YAML '

987+

'Yarn '

988+

'ZoKrates '

989+

'Zsh '

990+

)

991+

for i in "${specificLanguages[@]}"

919992

do

920-

if ./scc "examples/language/" | grep -q "$i "; then

993+

if ./scc "examples/language/" | grep -q "$i"; then

921994

echo -e "${GREEN}PASSED $i Language Check"

922995

else

923996

echo -e "${RED}======================================================="

@@ -944,7 +1017,7 @@ done

9441017

a=$(./scc "examples/issue345/" -f csv | sed -n '2 p')

9451018

b="C++,4,3,1,0,0,76,1,0"

9461019

if [ "$a" == "$b" ]; then

947-

echo -e "${GREEN}PASSED string termination check"

1020+

echo -e "${GREEN}PASSED String Termination Check"

9481021

else

9491022

echo -e "$a"

9501023

echo -e "${RED}======================================================="