local s1 = "hello world"
print("Test 1 - string.sub basic: " .. tostring(string.sub(s1, 1, 5) == "hello"))
print("Test 2 - string.sub negative end: " .. tostring(string.sub(s1, 7, -1) == "world"))
print("Test 3 - string.sub negative start: " .. tostring(string.sub(s1, -5) == "world"))
print("Test 4 - string.sub single char: " .. tostring(string.sub(s1, 1, 1) == "h"))
local start5, end5 = string.find("hello world", "world", 1, true)
print("Test 5 - string.find plain: " .. tostring(start5 == 7 and end5 == 11))
local start6, end6 = string.find("hello world", "hello")
print("Test 6 - string.find beginning: " .. tostring(start6 == 1 and end6 == 5))
local result7 = string.find("hello world", "xyz")
print("Test 7 - string.find not found: " .. tostring(result7 == nil))
local start8, end8 = string.find("hello123world", "%d+")
print("Test 8 - string.find pattern: " .. tostring(start8 == 6 and end8 == 8))
local start9, end9, cap9 = string.find("hello world", "(%a+) world")
print("Test 9 - string.find capture: " .. tostring(start9 == 1 and cap9 == "hello"))
local fmt10 = string.format("hello %s", "world")
print("Test 10 - string.format %%s: " .. tostring(fmt10 == "hello world"))
local fmt11 = string.format("value: %d", 42)
print("Test 11 - string.format %%d: " .. tostring(fmt11 == "value: 42"))
local fmt12 = string.format("pi: %.2f", 3.14159)
print("Test 12 - string.format %%.2f: " .. tostring(fmt12 == "pi: 3.14"))
local fmt13 = string.format("%s is %d years old", "Alice", 30)
print("Test 13 - string.format multiple: " .. tostring(fmt13 == "Alice is 30 years old"))
local fmt14 = string.format("100%% complete")
print("Test 14 - string.format %%%%: " .. tostring(fmt14 == "100% complete"))
print("Test 15 - string.len: " .. tostring(string.len("hello") == 5))
print("Test 16 - string.upper: " .. tostring(string.upper("hello") == "HELLO"))
print("Test 17 - string.lower: " .. tostring(string.lower("HELLO") == "hello"))
print("Test 18 - string.reverse: " .. tostring(string.reverse("hello") == "olleh"))
local start19, end19 = string.find("hello hello", "hello", 2)
print("Test 19 - string.find with init: " .. tostring(start19 == 7 and end19 == 11))
print("Test 20 - escape newline: " .. tostring(string.find("hello\nworld", "\n") == 6))
print("Test 21 - escape tab: " .. tostring(string.find("hello\tworld", "\t") == 6))
print("Test 22 - escape backslash: " .. tostring(string.find("hello\\world", "\\") == 6))
print("Test 23 - escape quote: " .. tostring(string.find("hello\"world", "\"") == 6))
print("Test 24 - escape single quote: " .. tostring(string.find('hello\'world', "'") == 6))
local with_newline = "a\nb"
print("Test 25 - newline length: " .. tostring(#with_newline == 3))
local with_tab = "a\tb"
print("Test 26 - tab length: " .. tostring(#with_tab == 3))
print("All string library tests complete!")