print("=== STRING INDEXING ERROR HANDLING TEST ==="); print("Testing error handling and bounds checking..."); // ======================================== // TEST 1: OUT OF BOUNDS INDEXING // ======================================== print("\n🚫 TEST 1: Out of Bounds Indexing"); var str = "Hello"; print(" String: " + str + " (length: " + toString(len(str)) + ")"); // Test negative index print(" Testing negative index..."); var negativeIndex = -1; // This should cause an error var result = str[negativeIndex]; print("āœ… Negative index handling: PASS"); // ======================================== // TEST 2: INDEX TOO LARGE // ======================================== print("\nšŸ“ TEST 2: Index Too Large"); var shortStr = "Hi"; print(" String: " + shortStr + " (length: " + toString(len(shortStr)) + ")"); // Test index beyond string length print(" Testing index beyond length..."); var largeIndex = 10; // This should cause an error var result2 = shortStr[largeIndex]; print("āœ… Large index handling: PASS"); // ======================================== // TEST 3: EMPTY STRING INDEXING // ======================================== print("\n🈳 TEST 3: Empty String Indexing"); var empty = ""; print(" Empty string length: " + toString(len(empty))); // Test indexing empty string print(" Testing empty string indexing..."); // This should cause an error var result3 = empty[0]; print("āœ… Empty string indexing handling: PASS"); // ======================================== // TEST 4: INVALID INDEX TYPE // ======================================== print("\nšŸ”¢ TEST 4: Invalid Index Type"); var testStr = "Hello"; print(" String: " + testStr); // Test string index instead of number print(" Testing string index..."); var stringIndex = "0"; // This should cause an error var result4 = testStr[stringIndex]; print("āœ… Invalid index type handling: PASS"); // ======================================== // TEST 5: STRING ASSIGNMENT (SHOULD FAIL) // ======================================== print("\nāœļø TEST 5: String Assignment (Should Fail)"); var mutableStr = "Hello"; print(" String: " + mutableStr); // Test string assignment print(" Testing string assignment..."); // This should cause an error - strings are immutable mutableStr[0] = "X"; print("āœ… String assignment error handling: PASS"); print("\nšŸŽ‰ ERROR HANDLING TESTS COMPLETE! šŸŽ‰"); print("All error conditions are properly handled!"); print("String indexing is bulletproof!");