Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lua/tests/gmod/unit/libraries/string/Left.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
return {
groupName = "string.Left",

cases = {
{
name = "Exists on the string table",
func = function()
expect( string.Left ).to.beA( "function" )
end
},

{
name = "Returns the expected string value",
func = function()
expect( string.Left( "Hello!", 1 ) ).to.equal( "H" )
expect( string.Left( "H", 1 ) ).to.equal( "H" )
expect( string.Left( "Hello!", 10 ) ).to.equal( "Hello!" )
expect( string.Left, nil ).to.errWith( [[bad argument #1 to 'Left' (string expected, got nil)]] )

Check failure on line 18 in lua/tests/gmod/unit/libraries/string/Left.lua

View workflow job for this annotation

GitHub Actions / run_tests (dev) / Run tests

Expected function: 0xe4adedba to error with 'bad argument #1 to 'Left' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 18 in lua/tests/gmod/unit/libraries/string/Left.lua

View workflow job for this annotation

GitHub Actions / run_tests (dev) / Run tests

Expected function: 0xe4adedba to error with 'bad argument #1 to 'Left' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 18 in lua/tests/gmod/unit/libraries/string/Left.lua

View workflow job for this annotation

GitHub Actions / run_tests (public) / Run tests

Expected function: 0xe3bcdbf2 to error with 'bad argument #1 to 'Left' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 18 in lua/tests/gmod/unit/libraries/string/Left.lua

View workflow job for this annotation

GitHub Actions / run_tests (public) / Run tests

Expected function: 0xe3bcdbf2 to error with 'bad argument #1 to 'Left' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 18 in lua/tests/gmod/unit/libraries/string/Left.lua

View workflow job for this annotation

GitHub Actions / run_tests (prerelease) / Run tests

Expected function: 0xe4ee9e7a to error with 'bad argument #1 to 'Left' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 18 in lua/tests/gmod/unit/libraries/string/Left.lua

View workflow job for this annotation

GitHub Actions / run_tests (prerelease) / Run tests

Expected function: 0xe4ee9e7a to error with 'bad argument #1 to 'Left' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 18 in lua/tests/gmod/unit/libraries/string/Left.lua

View workflow job for this annotation

GitHub Actions / run_tests (x86-64) / Run tests

Expected function: 0x80887f67c0ea496a to error with 'bad argument #1 to 'Left' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 18 in lua/tests/gmod/unit/libraries/string/Left.lua

View workflow job for this annotation

GitHub Actions / run_tests (x86-64) / Run tests

Expected function: 0x80887f67c0ea496a to error with 'bad argument #1 to 'Left' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'
expect( string.Left, nil, 1 ).to.errWith( [[bad argument #1 to 'Left' (string expected, got nil)]] )
expect( string.Left( "Hello!" ) ).to.equal( "Hello!" )
expect( string.Left( "Hello!", -1 ) ).to.equal( "Hello!" )
expect( string.Left( "Hello World!", -8 ) ).to.equal( "Hello" )
expect( string.Left( "garrys mod", 5 ) ).to.equal( "garry" )
end
}
}
}
27 changes: 27 additions & 0 deletions lua/tests/gmod/unit/libraries/string/Right.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
return {
groupName = "string.Right",

cases = {
{
name = "Exists on the string table",
func = function()
expect( string.Right ).to.beA( "function" )
end
},

{
name = "Returns the expected string value",
func = function()
expect( string.Right( "Hello!", 1 ) ).to.equal( "!" )
expect( string.Right( "H", 1 ) ).to.equal( "H" )
expect( string.Right( "Hello!", 10 ) ).to.equal( "Hello!" )
expect( string.Right, nil ).to.errWith( [[attempt to perform arithmetic on local 'num' (a nil value)]] )
expect( string.Right, nil, 1 ).to.errWith( [[bad argument #1 to 'Right' (string expected, got nil)]] )

Check failure on line 19 in lua/tests/gmod/unit/libraries/string/Right.lua

View workflow job for this annotation

GitHub Actions / run_tests (dev) / Run tests

Expected function: 0xe4acea62 to error with 'bad argument #1 to 'Right' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 19 in lua/tests/gmod/unit/libraries/string/Right.lua

View workflow job for this annotation

GitHub Actions / run_tests (dev) / Run tests

Expected function: 0xe4acea62 to error with 'bad argument #1 to 'Right' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 19 in lua/tests/gmod/unit/libraries/string/Right.lua

View workflow job for this annotation

GitHub Actions / run_tests (public) / Run tests

Expected function: 0xe3b92fe2 to error with 'bad argument #1 to 'Right' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 19 in lua/tests/gmod/unit/libraries/string/Right.lua

View workflow job for this annotation

GitHub Actions / run_tests (public) / Run tests

Expected function: 0xe3b92fe2 to error with 'bad argument #1 to 'Right' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 19 in lua/tests/gmod/unit/libraries/string/Right.lua

View workflow job for this annotation

GitHub Actions / run_tests (prerelease) / Run tests

Expected function: 0xe4eccf62 to error with 'bad argument #1 to 'Right' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 19 in lua/tests/gmod/unit/libraries/string/Right.lua

View workflow job for this annotation

GitHub Actions / run_tests (prerelease) / Run tests

Expected function: 0xe4eccf62 to error with 'bad argument #1 to 'Right' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 19 in lua/tests/gmod/unit/libraries/string/Right.lua

View workflow job for this annotation

GitHub Actions / run_tests (x86-64) / Run tests

Expected function: 0x80887f67c0ea4a3a to error with 'bad argument #1 to 'Right' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'

Check failure on line 19 in lua/tests/gmod/unit/libraries/string/Right.lua

View workflow job for this annotation

GitHub Actions / run_tests (x86-64) / Run tests

Expected function: 0x80887f67c0ea4a3a to error with 'bad argument #1 to 'Right' (string expected, got nil)', got 'bad argument #1 to '?' (string expected, got nil)'
expect( string.Right, "Hello!" ).to.errWith( [[attempt to perform arithmetic on local 'num' (a nil value)]] )
expect( string.Right( "Hello!", -1 ) ).to.equal( "Hello!" )
expect( string.Right( "Hello World!", -8 ) ).to.equal( "orld!" )
expect( string.Right( "garrys mod", 3 ) ).to.equal( "mod" )
end
}
}
}
Loading