diff --git a/lua/tests/gmod/unit/libraries/string/Left.lua b/lua/tests/gmod/unit/libraries/string/Left.lua new file mode 100644 index 0000000..6b39ac1 --- /dev/null +++ b/lua/tests/gmod/unit/libraries/string/Left.lua @@ -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)]] ) + 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 + } + } +} \ No newline at end of file diff --git a/lua/tests/gmod/unit/libraries/string/Right.lua b/lua/tests/gmod/unit/libraries/string/Right.lua new file mode 100644 index 0000000..1b22980 --- /dev/null +++ b/lua/tests/gmod/unit/libraries/string/Right.lua @@ -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)]] ) + 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 + } + } +} \ No newline at end of file