diff options
Diffstat (limited to 'tests/stylecheck')
-rw-r--r-- | tests/stylecheck/fileinfo.nim | 2 | ||||
-rw-r--r-- | tests/stylecheck/foreign_package/foreign_package.nim | 1 | ||||
-rw-r--r-- | tests/stylecheck/foreign_package/foreign_package.nimble | 2 | ||||
-rw-r--r-- | tests/stylecheck/t20397.nim | 4 | ||||
-rw-r--r-- | tests/stylecheck/t20397_1.nim | 8 | ||||
-rw-r--r-- | tests/stylecheck/t20397_2.nim | 7 | ||||
-rw-r--r-- | tests/stylecheck/taccept.nim | 22 | ||||
-rw-r--r-- | tests/stylecheck/tforeign_package.nim | 16 | ||||
-rw-r--r-- | tests/stylecheck/thint.nim | 43 | ||||
-rw-r--r-- | tests/stylecheck/treject.nim | 17 | ||||
-rw-r--r-- | tests/stylecheck/tusages.nim | 22 |
11 files changed, 144 insertions, 0 deletions
diff --git a/tests/stylecheck/fileinfo.nim b/tests/stylecheck/fileinfo.nim new file mode 100644 index 000000000..d6faf0c73 --- /dev/null +++ b/tests/stylecheck/fileinfo.nim @@ -0,0 +1,2 @@ +# fileinfo.nim +type FileInfo* = object \ No newline at end of file diff --git a/tests/stylecheck/foreign_package/foreign_package.nim b/tests/stylecheck/foreign_package/foreign_package.nim new file mode 100644 index 000000000..f95be006c --- /dev/null +++ b/tests/stylecheck/foreign_package/foreign_package.nim @@ -0,0 +1 @@ +include ../thint \ No newline at end of file diff --git a/tests/stylecheck/foreign_package/foreign_package.nimble b/tests/stylecheck/foreign_package/foreign_package.nimble new file mode 100644 index 000000000..a2c49e389 --- /dev/null +++ b/tests/stylecheck/foreign_package/foreign_package.nimble @@ -0,0 +1,2 @@ +# See `tstyleCheck` +# Needed to mark `mstyleCheck` as a foreign package. diff --git a/tests/stylecheck/t20397.nim b/tests/stylecheck/t20397.nim new file mode 100644 index 000000000..486a97d73 --- /dev/null +++ b/tests/stylecheck/t20397.nim @@ -0,0 +1,4 @@ +{.hintAsError[Name]:on.} +var a_b = 1 +discard a_b +{.hintAsError[Name]:off.} \ No newline at end of file diff --git a/tests/stylecheck/t20397_1.nim b/tests/stylecheck/t20397_1.nim new file mode 100644 index 000000000..76c03dca1 --- /dev/null +++ b/tests/stylecheck/t20397_1.nim @@ -0,0 +1,8 @@ +discard """ + matrix: "--styleCheck:off --hint:Name:on" +""" + +{.hintAsError[Name]:on.} +var a_b = 1 +discard a_b +{.hintAsError[Name]:off.} diff --git a/tests/stylecheck/t20397_2.nim b/tests/stylecheck/t20397_2.nim new file mode 100644 index 000000000..3b8e1c4d6 --- /dev/null +++ b/tests/stylecheck/t20397_2.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "'a_b' should be: 'aB'" + matrix: "--styleCheck:error" +""" + +var a_b = 1 +discard a_b \ No newline at end of file diff --git a/tests/stylecheck/taccept.nim b/tests/stylecheck/taccept.nim new file mode 100644 index 000000000..43a9ab71f --- /dev/null +++ b/tests/stylecheck/taccept.nim @@ -0,0 +1,22 @@ +discard """ + matrix: "--styleCheck:error --styleCheck:usages" +""" + +import std/[asyncdispatch, nre] + +type + Name = object + id: int + +template hello = + var iD = "string" + var name: Name + doAssert name.id == 0 + doAssert iD == "string" + +hello() + +# bug #12955 +import os +import fileinfo +var xs: seq[fileinfo.FileInfo] diff --git a/tests/stylecheck/tforeign_package.nim b/tests/stylecheck/tforeign_package.nim new file mode 100644 index 000000000..8594ad802 --- /dev/null +++ b/tests/stylecheck/tforeign_package.nim @@ -0,0 +1,16 @@ +discard """ + matrix: "--errorMax:0 --styleCheck:error" + action: compile +""" + +import foreign_package/foreign_package + +# This call tests that: +# - an instantiation of a generic in a foreign package doesn't raise errors +# when the generic body contains: +# - definition and usage violations +# - builtin pragma usage violations +# - user pragma usage violations +# - definition violations in foreign packages are ignored +# - usage violations in foreign packages are ignored +genericProc[int]() diff --git a/tests/stylecheck/thint.nim b/tests/stylecheck/thint.nim new file mode 100644 index 000000000..c19aac1b8 --- /dev/null +++ b/tests/stylecheck/thint.nim @@ -0,0 +1,43 @@ +discard """ + matrix: "--styleCheck:hint" + action: compile +""" + +# Test violating ident definition: +{.pragma: user_pragma.} #[tt.Hint + ^ 'user_pragma' should be: 'userPragma' [Name] ]# + +# Test violating ident usage style matches definition style: +{.userPragma.} #[tt.Hint + ^ 'userPragma' should be: 'user_pragma' [template declared in thint.nim(7, 9)] [Name] ]# + +# Test violating builtin pragma usage style: +{.no_side_effect.}: #[tt.Hint + ^ 'no_side_effect' should be: 'noSideEffect' [Name] ]# + discard 0 + +# Test: +# - definition style violation +# - user pragma usage style violation +# - builtin pragma usage style violation +proc generic_proc*[T] {.no_destroy, userPragma.} = #[tt.Hint + ^ 'generic_proc' should be: 'genericProc' [Name]; tt.Hint + ^ 'no_destroy' should be: 'nodestroy' [Name]; tt.Hint + ^ 'userPragma' should be: 'user_pragma' [template declared in thint.nim(7, 9)] [Name] ]# + # Test definition style violation: + let snake_case = 0 #[tt.Hint + ^ 'snake_case' should be: 'snakeCase' [Name] ]# + # Test user pragma definition style violation: + {.pragma: another_user_pragma.} #[tt.Hint + ^ 'another_user_pragma' should be: 'anotherUserPragma' [Name] ]# + # Test user pragma usage style violation: + {.anotherUserPragma.} #[tt.Hint + ^ 'anotherUserPragma' should be: 'another_user_pragma' [template declared in thint.nim(31, 11)] [Name] ]# + # Test violating builtin pragma usage style: + {.no_side_effect.}: #[tt.Hint + ^ 'no_side_effect' should be: 'noSideEffect' [Name] ]# + # Test usage style violation: + discard snakeCase #[tt.Hint + ^ 'snakeCase' should be: 'snake_case' [let declared in thint.nim(28, 7)] [Name] ]# + +generic_proc[int]() diff --git a/tests/stylecheck/treject.nim b/tests/stylecheck/treject.nim new file mode 100644 index 000000000..458a2d039 --- /dev/null +++ b/tests/stylecheck/treject.nim @@ -0,0 +1,17 @@ +discard """ + action: reject + nimout: '''treject.nim(14, 13) Error: 'iD' should be: 'id' [field declared in treject.nim(9, 5)]''' + matrix: "--styleCheck:error --styleCheck:usages --hint:Name:on" +""" + +type + Name = object + id: int + +template hello = + var iD = "string" + var name: Name + echo name.iD + echo iD + +hello() diff --git a/tests/stylecheck/tusages.nim b/tests/stylecheck/tusages.nim new file mode 100644 index 000000000..b689dabb3 --- /dev/null +++ b/tests/stylecheck/tusages.nim @@ -0,0 +1,22 @@ +discard """ + action: reject + nimout: '''tusages.nim(20, 5) Error: 'BAD_STYLE' should be: 'BADSTYLE' [proc declared in tusages.nim(9, 6)]''' + matrix: "--styleCheck:error --styleCheck:usages --hint:all:off --hint:Name:on" +""" + +import strutils + +proc BADSTYLE(c: char) = discard + +proc toSnakeCase(s: string): string = + result = newStringOfCap(s.len + 3) + for i in 0..<s.len: + if s[i] in {'A'..'Z'}: + if i > 0 and s[i-1] in {'a'..'z'}: + result.add '_' + result.add toLowerAscii(s[i]) + else: + result.add s[i] + BAD_STYLE(s[i]) + +echo toSnakeCase("fooBarBaz Yes") |