From e0eaf5c3e5e3711dca1cdc3f0863aa26c784d312 Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Tue, 1 Jul 2025 14:11:22 -0400 Subject: [PATCH 1/3] Add string.Left/string.Right --- lua/tests/gmod/unit/libraries/string/Left.lua | 26 +++++++++++++++++++ .../gmod/unit/libraries/string/Right.lua | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 lua/tests/gmod/unit/libraries/string/Left.lua create mode 100644 lua/tests/gmod/unit/libraries/string/Right.lua 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..ad91707 --- /dev/null +++ b/lua/tests/gmod/unit/libraries/string/Left.lua @@ -0,0 +1,26 @@ +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']] ) + expect( string.Left( nil, 1 ) ).to.errWith( [[bad argument #1 to 'Left']] ) + expect( string.Left( "Hello!" ) ).to.equal( "Hello!" ) + expect( string.Left( "Hello!", -1 ) ).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..5e21e59 --- /dev/null +++ b/lua/tests/gmod/unit/libraries/string/Right.lua @@ -0,0 +1,26 @@ +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']] ) + expect( string.Right( nil, 1 ) ).to.errWith( [[bad argument #1 to 'Right']] ) + expect( string.Right( "Hello!" ) ).to.errWith( [[attempt to perform arithmetic on local 'num']] ) + expect( string.Right( "Hello!", -1 ) ).to.equal( "Hello!" ) + expect( string.Right( "garrys mod", 3 ) ).to.equal( "mod" ) + end + } + } +} \ No newline at end of file From 1517764fafd6fa53985fc98eb95af91f9ea47b9f Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Mon, 29 Sep 2025 23:38:08 -0400 Subject: [PATCH 2/3] Fix tests --- lua/tests/gmod/unit/libraries/string/Left.lua | 5 +++-- lua/tests/gmod/unit/libraries/string/Right.lua | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lua/tests/gmod/unit/libraries/string/Left.lua b/lua/tests/gmod/unit/libraries/string/Left.lua index ad91707..72c7c8d 100644 --- a/lua/tests/gmod/unit/libraries/string/Left.lua +++ b/lua/tests/gmod/unit/libraries/string/Left.lua @@ -15,10 +15,11 @@ return { 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']] ) - expect( string.Left( nil, 1 ) ).to.errWith( [[bad argument #1 to 'Left']] ) + 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 } diff --git a/lua/tests/gmod/unit/libraries/string/Right.lua b/lua/tests/gmod/unit/libraries/string/Right.lua index 5e21e59..61ceb41 100644 --- a/lua/tests/gmod/unit/libraries/string/Right.lua +++ b/lua/tests/gmod/unit/libraries/string/Right.lua @@ -15,10 +15,11 @@ return { 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']] ) - expect( string.Right( nil, 1 ) ).to.errWith( [[bad argument #1 to 'Right']] ) - expect( string.Right( "Hello!" ) ).to.errWith( [[attempt to perform arithmetic on local 'num']] ) + 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 } From 30e95901c3c3dbe2c564c136e5efd063e3971170 Mon Sep 17 00:00:00 2001 From: thecraftianman <64441307+thecraftianman@users.noreply.github.com> Date: Tue, 30 Sep 2025 12:04:52 -0400 Subject: [PATCH 3/3] Fix error test case formatting --- lua/tests/gmod/unit/libraries/string/Left.lua | 4 ++-- lua/tests/gmod/unit/libraries/string/Right.lua | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/tests/gmod/unit/libraries/string/Left.lua b/lua/tests/gmod/unit/libraries/string/Left.lua index 72c7c8d..6b39ac1 100644 --- a/lua/tests/gmod/unit/libraries/string/Left.lua +++ b/lua/tests/gmod/unit/libraries/string/Left.lua @@ -15,8 +15,8 @@ return { 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, 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" ) diff --git a/lua/tests/gmod/unit/libraries/string/Right.lua b/lua/tests/gmod/unit/libraries/string/Right.lua index 61ceb41..1b22980 100644 --- a/lua/tests/gmod/unit/libraries/string/Right.lua +++ b/lua/tests/gmod/unit/libraries/string/Right.lua @@ -15,9 +15,9 @@ return { 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, 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" )