Browse Source

Added tests and docs

Steven Hall 8 years ago
parent
commit
00275de6a5

+ 9 - 0
docs/types.html

@@ -115,9 +115,18 @@
 
 	n = "A".repeat(10)      // n is now "AAAAAAAAAA"
 
+	// upper() and lower() operate on the whole string when 0 arguments are passed
 	n = b.upper()           // n is now "HELLO WORLD"
 	n = b.lower()           // n is now "hello world"
 
+	// upper() and lower() can both take multiple string or integer arguments
+	n = b.upper("He", "d")  // n is now "HEllo WordD"
+	n = b.lower(-1, -5)     // n is now "Hello world"
+
+	// upper() and lower() can also take multiple mixed arguments
+	n = b.upper("He", -1)   // n is now "HEllo WordD"
+	n = b.lower(-1, "W")    // n is now "Hello world"
+
 	// You are also able to edit strings by character...
 	b[0] = "Z"              // b is now "Zello World"
 	b[1] = "abc"            // b is now "Zabco World"

+ 46 - 0
test/string/lower_method.gravity

@@ -0,0 +1,46 @@
+#unittest {
+	name: "lower() methods for string -- complex";
+	error: NONE;
+	result: true;
+};
+
+func main () {
+	var s = "tHIS IS JUST A REALLY LONG TEST STRING TO TRY AND GET AS much VARIATION AS POSSIBLE"
+
+	var a_str = s.lower("V") == "tHIS IS JUST A REALLY LONG TEST STRING TO TRY AND GET AS much vARIATION AS POSSIBLE"
+	if (a_str == false) { System.print("a) string failed\n"); return false }
+
+	var b_str = s.lower("I") == "tHiS iS JUST A REALLY LONG TEST STRiNG TO TRY AND GET AS much VARiATiON AS POSSiBLE"
+	if (a_str == false) { System.print("b) string failed\n"); return false }
+
+	var c_str = s.lower("IS") == "tHis is JUST A REALLY LONG TEST STRING TO TRY AND GET AS much VARIATION AS POSSIBLE"
+	if (a_str == false) { System.print("c) string failed\n"); return false }
+
+	// Try a character that is already lower
+	var d_str = s.lower("h V") == "tHIS IS JUST A REALLY LONG TEST STRING TO TRY AND GET AS much vARIATION AS POSSIBLE"
+	if (a_str == false) { System.print("d) string failed\n"); return false }
+
+	var e_str = s.lower("muc") == "tHIS IS JUST A REALLY LONG TEST STRING TO TRY AND GET AS much VARIATION AS POSSIBLE"
+	if (a_str == false) { System.print("e) string failed\n"); return false }
+
+
+	// Numbers Only
+	// The V in VARIATION
+	var a_int = s.lower(62) == "tHIS IS JUST A REALLY LONG TEST STRING TO TRY AND GET AS much vARIATION AS POSSIBLE"
+	if (a_int == false) { System.print("a) int failed\n"); return false }
+
+	var b_int = s.lower(-21) == s.lower(62)
+	if (a_int == false) { System.print("b) int failed\n"); return false }
+
+	var c_int = s.lower(2) == "tHiS IS JUST A REALLY LONG TEST STRING TO TRY AND GET AS much VARIATION AS POSSIBLE"
+	if (a_int == false) { System.print("c) int failed\n"); return false }
+
+	var d_int = s.lower(-81) == s.lower(2)
+	if (a_int == false) { System.print("d) int failed\n"); return false }
+
+	// Try a character that is already lowercase
+	var e_int = s.lower(0) == "tHIS IS JUST A REALLY LONG TEST STRING TO TRY AND GET AS much VARIATION AS POSSIBLE"
+	if (a_int == false) { System.print("e) int failed\n"); return false }
+	
+	return true
+}

+ 0 - 0
test/string/upper_lower_method.gravity → test/string/upper_lower_method_simple.gravity


+ 41 - 0
test/string/upper_lower_multiple_args.gravity

@@ -0,0 +1,41 @@
+#unittest {
+	name: "upper() methods for string -- multiple args";
+	error: NONE;
+	result: true;
+};
+
+func main () {
+	var s = "This is just a really long test string to try and get as MUCH variation as possible"
+
+	// UPPER
+	var a = s.upper("v", 1) == "THis is just a really long test string to try and get as MUCH Variation as possible"
+	if (a == false) { System.print("a) upper failed"); return false }
+
+	// Try swappings the order
+	var b = s.upper(1, "v") == s.upper("v", 1)
+	if (b == false) { System.print("b) upper failed"); return false }
+
+	var c = s.upper("really", "MUCH", -1 "tr") == "This is just a REALLY long test sTRing to TRy and get as MUCH variation as possiblE"
+	if (c == false) { System.print("c) upper failed"); return false }
+
+	// Try a different order
+	var d = s.upper(-1, "tr", "really", "MUCH") == s.upper("really", "MUCH", -1 "tr")
+	if (d == false) { System.print("d) upper failed"); return false }
+
+
+	// LOWER
+	a = s.lower("M", 0) == "this is just a really long test string to try and get as mUCH variation as possible"
+	if (a == false) { System.print("a) lower failed"); return false }
+
+	b = s.lower(0, "M") == s.lower("M", 0)
+	if (b == false) { System.print("b) lower failed"); return false }
+
+	c = s.lower("REALLY", "MU", -83 "H") == "this is just a really long test string to try and get as muCh variation as possible"
+	if (c == false) { System.print("c) lower failed"); return false }
+
+	// Try a different order
+	d = s.lower(-83, "H", "REALLY", "MU") == s.lower("REALLY", "MU", -83 "H")
+	if (d == false) { System.print("d) lower failed"); return false }
+
+	return true
+}

+ 50 - 0
test/string/upper_method.gravity

@@ -0,0 +1,50 @@
+#unittest {
+	name: "upper() methods for string -- complex";
+	error: NONE;
+	result: true;
+};
+
+func main () {
+	var s = "This is just a really long test string to try and get as MUCH variation as possible"
+
+	// 1 match
+	var a_str = s.upper("v") == "This is just a really long test string to try and get as MUCH Variation as possible"
+	if (a_str == false) { System.print("a) string failed"); return false }
+
+	// multiple matches
+	var b_str = s.upper("i") == "ThIs Is just a really long test strIng to try and get as MUCH varIatIon as possIble"
+	if (b_str == false) { System.print("b) string failed"); return false }
+
+	// 1 match, longer search string
+	var c_str = s.upper("is") == "ThIS IS just a really long test string to try and get as MUCH variation as possible"
+	if (c_str == false) { System.print("c) string failed"); return false }
+
+	// Try a character that is already uppercase, combined with a lowercase
+	var d_str = s.upper("Th") == "THis is just a really long test string to try and get as MUCH variation as possible"
+	if (d_str == false) { System.print("d) string failed"); return false }
+
+	// Try a completely uppercase string
+	var e_str = s.upper("MUC") == "This is just a really long test string to try and get as MUCH variation as possible"
+	if (e_str == false) { System.print("e) string failed"); return false }
+
+
+	// Numbers Only
+	// the v in variation
+	var a_int = s.upper(62) == "This is just a really long test string to try and get as MUCH Variation as possible"
+	if (a_int == false) { System.print("a) int failed"); return false }
+
+	var b_int = s.upper(-21) == s.upper(62)
+	if (b_int == false) { System.print("b) int failed"); return false }
+
+	var c_int = s.upper(2) == "ThIs is just a really long test string to try and get as MUCH variation as possible"
+	if (c_int == false) { System.print("c) int failed"); return false }
+
+	var d_int = s.upper(-81) == s.upper(2)
+	if (d_int == false) { System.print("d) int failed"); return false }
+
+	// Try a character that is already uppercase
+	var e_int = s.upper(0) == "This is just a really long test string to try and get as MUCH variation as possible"
+	if (e_int == false) { System.print("e) int failed"); return false }
+	
+	return true
+}