Skip to content

Commit af8bf3f

Browse files
authored
Merge pull request #8 from apiiro/noy/LIM-24152/addFortranLanguage
Add fortran language to complexity
2 parents dfb3444 + 974b8ab commit af8bf3f

File tree

6 files changed

+504
-7
lines changed

6 files changed

+504
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Following languages are currently supported:
118118
* Rust
119119
* Scala
120120
* Php
121+
* Fortran
121122

122123
### Credits
123124

calculate/calculate_test.go

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ func TestIncludeExcludePatterns(t *testing.T) {
6868
touch(filepath.Join(basePath, "b.js"))
6969
touch(filepath.Join(basePath, "src", "svc.java"))
7070
touch(filepath.Join(basePath, "src", "api.js"))
71+
touch(filepath.Join(basePath, "src", "foo.F15"))
7172
touch(filepath.Join(basePath, "src", "nested", "util.js"))
73+
touch(filepath.Join(basePath, "src", "nested", "util2.f90"))
7274

7375
filesCount, err := getFileCount(
7476
basePath,
@@ -89,14 +91,16 @@ func TestIncludeExcludePatterns(t *testing.T) {
8991
},
9092
)
9193
r.Nil(err)
92-
r.Equal(float64(4), filesCount)
94+
r.Equal(float64(6), filesCount)
9395

9496
filesCount, err = getFileCount(
9597
basePath,
9698
[]string{},
9799
[]string{
98100
"*/*.java",
99101
"a.js",
102+
"**/nested/util2.f90",
103+
"**/foo.F15",
100104
},
101105
)
102106
r.Nil(err)
@@ -198,8 +202,8 @@ func TestDogFood(t *testing.T) {
198202
inRange(r, total.Lines, 2000, 4000)
199203
inRange(r, total.LinesOfCode, 2000, 4000)
200204
inRange(r, total.Keywords, 200, 400)
201-
inRange(r, total.Indentations, 2500, 3500)
202-
inRange(r, total.IndentationsNormalized, 2500, 3500)
205+
inRange(r, total.Indentations, 2500, 3700)
206+
inRange(r, total.IndentationsNormalized, 2500, 3700)
203207
inRange(r, total.IndentationsDiff, 400, 600)
204208
inRange(r, total.IndentationsDiffNormalized, 400, 600)
205209
inRange(r, total.IndentationsComplexity, 11, 13)
@@ -208,10 +212,10 @@ func TestDogFood(t *testing.T) {
208212

209213
average := summary.CountersByLanguage["go"].Average
210214
inRange(r, average.Lines, 300, 400)
211-
inRange(r, average.LinesOfCode, 250, 300)
215+
inRange(r, average.LinesOfCode, 250, 330)
212216
inRange(r, average.Keywords, 30, 40)
213-
inRange(r, average.Indentations, 350, 400)
214-
inRange(r, average.IndentationsNormalized, 350, 400)
217+
inRange(r, average.Indentations, 350, 420)
218+
inRange(r, average.IndentationsNormalized, 350, 420)
215219
inRange(r, average.IndentationsDiff, 60, 70)
216220
inRange(r, average.IndentationsDiffNormalized, 60, 70)
217221
inRange(r, average.IndentationsComplexity, 1, 2)
@@ -2055,3 +2059,59 @@ func TestCountersForPhpFullSample(t *testing.T) {
20552059
r.Equal(float64(144), math.Round(counters.IndentationsComplexity*100))
20562060
r.Equal(float64(21), math.Round(counters.IndentationsDiffComplexity*100))
20572061
}
2062+
2063+
func TestCountersForFortran(t *testing.T) {
2064+
r := assert.New(t)
2065+
2066+
// language=Fortran
2067+
code := `
2068+
program factorial
2069+
implicit none
2070+
integer :: n, fact, i
2071+
2072+
! Prompt user for input
2073+
print *, "Enter a positive integer:"
2074+
read *, n
2075+
2076+
fact = 1 ! Initialize factorial
2077+
2078+
! Calculate factorial
2079+
do i = 1, n
2080+
fact = fact * i
2081+
end do
2082+
2083+
! Output the result
2084+
print *, "Factorial of", n, "is", fact
2085+
end program factorial
2086+
`
2087+
counters, err := getCountersForCode(code, "fortran")
2088+
r.Nil(err)
2089+
r.NotNil(counters)
2090+
2091+
r.Equal(float64(20), counters.Lines)
2092+
r.Equal(float64(14), counters.LinesOfCode)
2093+
r.Equal(float64(8), counters.Keywords)
2094+
r.Equal(float64(52), counters.Indentations)
2095+
r.Equal(float64(13), math.Round(counters.IndentationsNormalized))
2096+
r.Equal(float64(8), math.Round(counters.IndentationsDiff))
2097+
r.Equal(float64(2), math.Round(counters.IndentationsDiffNormalized))
2098+
}
2099+
2100+
func TestCountersForFortranFullSample(t *testing.T) {
2101+
r := assert.New(t)
2102+
2103+
counters, err := getCountersForCode(test_resources.FortranCode, "fortran")
2104+
r.Nil(err)
2105+
r.NotNil(counters)
2106+
2107+
r.Equal(float64(346), counters.Lines)
2108+
r.Equal(float64(306), counters.LinesOfCode)
2109+
r.Equal(float64(146), counters.Keywords)
2110+
r.Equal(float64(2376), counters.Indentations)
2111+
r.Equal(float64(594), math.Round(counters.IndentationsNormalized))
2112+
r.Equal(float64(160), math.Round(counters.IndentationsDiff))
2113+
r.Equal(float64(40), math.Round(counters.IndentationsDiffNormalized))
2114+
r.Equal(float64(48), math.Round(counters.KeywordsComplexity*100))
2115+
r.Equal(float64(194), math.Round(counters.IndentationsComplexity*100))
2116+
r.Equal(float64(13), math.Round(counters.IndentationsDiffComplexity*100))
2117+
}

calculate/keywords.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,92 @@ var languageToKeywords = map[Language][]string{
427427
"xor",
428428
"yield",
429429
},
430+
"fortran": {
431+
"abstract",
432+
"allocatable",
433+
"allocate",
434+
"assign",
435+
"associate",
436+
"asynchronous",
437+
"backspace",
438+
"block",
439+
"block data",
440+
"case",
441+
"codimension",
442+
"common",
443+
"contains",
444+
"contiguous",
445+
"critical",
446+
"cycle",
447+
"data",
448+
"deallocate",
449+
"deferred",
450+
"do",
451+
"do concurrent",
452+
"else",
453+
"else if",
454+
"end",
455+
"endfile",
456+
"endif",
457+
"entry",
458+
"equivalence",
459+
"external",
460+
"final",
461+
"flush",
462+
"format",
463+
"forall",
464+
"function",
465+
"generic",
466+
"goto",
467+
"if",
468+
"implicit",
469+
"include",
470+
"inquire",
471+
"intrinsic",
472+
"lock",
473+
"module",
474+
"namelist",
475+
"nullify",
476+
"only",
477+
"operator",
478+
"optional",
479+
"pause",
480+
"pass",
481+
"pointer",
482+
"procedure",
483+
"program",
484+
"private",
485+
"public",
486+
"recursive",
487+
"result",
488+
"rewrite",
489+
"save",
490+
"select",
491+
"select rank",
492+
"sequence",
493+
"stop",
494+
"submodule",
495+
"subroutine",
496+
"sync all",
497+
"sync images",
498+
"sync memory",
499+
"target",
500+
"then",
501+
"use",
502+
"volatile",
503+
"wait",
504+
"while",
505+
"write",
506+
"impure",
507+
"error stop",
508+
"non_overridable",
509+
"non_recursive",
510+
"import (in interfaces)",
511+
"element",
512+
"elemental",
513+
"extend",
514+
"enumerator",
515+
},
430516
}
431517

432518
var languagesWithAtSignPrefix = map[Language]bool{

calculate/langauges.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var languageToExtensions = map[Language][]string{
1717
"rust": {"rs"},
1818
"scala": {"scala", "sc"},
1919
"php": {"php", "phtml", "php3", "php4", "php5", "php7", "phps", "pht", "phar"},
20+
"fortran": {"f", "for", "f77", "f90", "f95", "f03", "f03p", "f08", "f08p", "f15", "f20", "f18", "f2k", "f2003", "f2008", "f2015", "f2018", "fpp", "ftn", "f05", "F", "FOR", "F77", "F90", "F95", "F03", "F08", "F15", "F18", "F2K", "F2003", "F2015", "F2008", "F2018", "FPP", "FTN"},
2021
}
2122

2223
var extensionToLanguage = make(map[Language]string)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/urfave/cli/v2"
1212
)
1313

14-
const VERSION = "1.0.7"
14+
const VERSION = "1.0.8"
1515

1616
func main() {
1717
cli.AppHelpTemplate =

0 commit comments

Comments
 (0)