1" Tests for various functions. 2 3func Test_str2nr() 4 call assert_equal(0, str2nr('')) 5 call assert_equal(1, str2nr('1')) 6 call assert_equal(1, str2nr(' 1 ')) 7 8 call assert_equal(1, str2nr('+1')) 9 call assert_equal(1, str2nr('+ 1')) 10 call assert_equal(1, str2nr(' + 1 ')) 11 12 call assert_equal(-1, str2nr('-1')) 13 call assert_equal(-1, str2nr('- 1')) 14 call assert_equal(-1, str2nr(' - 1 ')) 15 16 call assert_equal(123456789, str2nr('123456789')) 17 call assert_equal(-123456789, str2nr('-123456789')) 18endfunc 19 20func Test_tolower() 21 call assert_equal("", tolower("")) 22 23 " Test with all printable ASCII characters. 24 call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~', 25 \ tolower(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) 26 27 if !has('multi_byte') 28 return 29 endif 30 31 " Test with a few uppercase diacritics. 32 call assert_equal("aàáâãäåāăąǎǟǡả", tolower("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) 33 call assert_equal("bḃḇ", tolower("BḂḆ")) 34 call assert_equal("cçćĉċč", tolower("CÇĆĈĊČ")) 35 call assert_equal("dďđḋḏḑ", tolower("DĎĐḊḎḐ")) 36 call assert_equal("eèéêëēĕėęěẻẽ", tolower("EÈÉÊËĒĔĖĘĚẺẼ")) 37 call assert_equal("fḟ ", tolower("FḞ ")) 38 call assert_equal("gĝğġģǥǧǵḡ", tolower("GĜĞĠĢǤǦǴḠ")) 39 call assert_equal("hĥħḣḧḩ", tolower("HĤĦḢḦḨ")) 40 call assert_equal("iìíîïĩīĭįiǐỉ", tolower("IÌÍÎÏĨĪĬĮİǏỈ")) 41 call assert_equal("jĵ", tolower("JĴ")) 42 call assert_equal("kķǩḱḵ", tolower("KĶǨḰḴ")) 43 call assert_equal("lĺļľŀłḻ", tolower("LĹĻĽĿŁḺ")) 44 call assert_equal("mḿṁ", tolower("MḾṀ")) 45 call assert_equal("nñńņňṅṉ", tolower("NÑŃŅŇṄṈ")) 46 call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) 47 call assert_equal("pṕṗ", tolower("PṔṖ")) 48 call assert_equal("q", tolower("Q")) 49 call assert_equal("rŕŗřṙṟ", tolower("RŔŖŘṘṞ")) 50 call assert_equal("sśŝşšṡ", tolower("SŚŜŞŠṠ")) 51 call assert_equal("tţťŧṫṯ", tolower("TŢŤŦṪṮ")) 52 call assert_equal("uùúûüũūŭůűųưǔủ", tolower("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) 53 call assert_equal("vṽ", tolower("VṼ")) 54 call assert_equal("wŵẁẃẅẇ", tolower("WŴẀẂẄẆ")) 55 call assert_equal("xẋẍ", tolower("XẊẌ")) 56 call assert_equal("yýŷÿẏỳỷỹ", tolower("YÝŶŸẎỲỶỸ")) 57 call assert_equal("zźżžƶẑẕ", tolower("ZŹŻŽƵẐẔ")) 58 59 " Test with a few lowercase diacritics, which should remain unchanged. 60 call assert_equal("aàáâãäåāăąǎǟǡả", tolower("aàáâãäåāăąǎǟǡả")) 61 call assert_equal("bḃḇ", tolower("bḃḇ")) 62 call assert_equal("cçćĉċč", tolower("cçćĉċč")) 63 call assert_equal("dďđḋḏḑ", tolower("dďđḋḏḑ")) 64 call assert_equal("eèéêëēĕėęěẻẽ", tolower("eèéêëēĕėęěẻẽ")) 65 call assert_equal("fḟ", tolower("fḟ")) 66 call assert_equal("gĝğġģǥǧǵḡ", tolower("gĝğġģǥǧǵḡ")) 67 call assert_equal("hĥħḣḧḩẖ", tolower("hĥħḣḧḩẖ")) 68 call assert_equal("iìíîïĩīĭįǐỉ", tolower("iìíîïĩīĭįǐỉ")) 69 call assert_equal("jĵǰ", tolower("jĵǰ")) 70 call assert_equal("kķǩḱḵ", tolower("kķǩḱḵ")) 71 call assert_equal("lĺļľŀłḻ", tolower("lĺļľŀłḻ")) 72 call assert_equal("mḿṁ ", tolower("mḿṁ ")) 73 call assert_equal("nñńņňʼnṅṉ", tolower("nñńņňʼnṅṉ")) 74 call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("oòóôõöøōŏőơǒǫǭỏ")) 75 call assert_equal("pṕṗ", tolower("pṕṗ")) 76 call assert_equal("q", tolower("q")) 77 call assert_equal("rŕŗřṙṟ", tolower("rŕŗřṙṟ")) 78 call assert_equal("sśŝşšṡ", tolower("sśŝşšṡ")) 79 call assert_equal("tţťŧṫṯẗ", tolower("tţťŧṫṯẗ")) 80 call assert_equal("uùúûüũūŭůűųưǔủ", tolower("uùúûüũūŭůűųưǔủ")) 81 call assert_equal("vṽ", tolower("vṽ")) 82 call assert_equal("wŵẁẃẅẇẘ", tolower("wŵẁẃẅẇẘ")) 83 call assert_equal("ẋẍ", tolower("ẋẍ")) 84 call assert_equal("yýÿŷẏẙỳỷỹ", tolower("yýÿŷẏẙỳỷỹ")) 85 call assert_equal("zźżžƶẑẕ", tolower("zźżžƶẑẕ")) 86 87 " According to https://twitter.com/jifa/status/625776454479970304 88 " Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase 89 " in length (2 to 3 bytes) when lowercased. So let's test them. 90 call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ")) 91endfunc 92 93func Test_toupper() 94 call assert_equal("", toupper("")) 95 96 " Test with all printable ASCII characters. 97 call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~', 98 \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) 99 100 if !has('multi_byte') 101 return 102 endif 103 104 " Test with a few lowercase diacritics. 105 call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("aàáâãäåāăąǎǟǡả")) 106 call assert_equal("BḂḆ", toupper("bḃḇ")) 107 call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč")) 108 call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ")) 109 call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("eèéêëēĕėęěẻẽ")) 110 call assert_equal("FḞ", toupper("fḟ")) 111 call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("gĝğġģǥǧǵḡ")) 112 call assert_equal("HĤĦḢḦḨẖ", toupper("hĥħḣḧḩẖ")) 113 call assert_equal("IÌÍÎÏĨĪĬĮǏỈ", toupper("iìíîïĩīĭįǐỉ")) 114 call assert_equal("JĴǰ", toupper("jĵǰ")) 115 call assert_equal("KĶǨḰḴ", toupper("kķǩḱḵ")) 116 call assert_equal("LĹĻĽĿŁḺ", toupper("lĺļľŀłḻ")) 117 call assert_equal("MḾṀ ", toupper("mḿṁ ")) 118 call assert_equal("NÑŃŅŇʼnṄṈ", toupper("nñńņňʼnṅṉ")) 119 call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("oòóôõöøōŏőơǒǫǭỏ")) 120 call assert_equal("PṔṖ", toupper("pṕṗ")) 121 call assert_equal("Q", toupper("q")) 122 call assert_equal("RŔŖŘṘṞ", toupper("rŕŗřṙṟ")) 123 call assert_equal("SŚŜŞŠṠ", toupper("sśŝşšṡ")) 124 call assert_equal("TŢŤŦṪṮẗ", toupper("tţťŧṫṯẗ")) 125 call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("uùúûüũūŭůűųưǔủ")) 126 call assert_equal("VṼ", toupper("vṽ")) 127 call assert_equal("WŴẀẂẄẆẘ", toupper("wŵẁẃẅẇẘ")) 128 call assert_equal("ẊẌ", toupper("ẋẍ")) 129 call assert_equal("YÝŸŶẎẙỲỶỸ", toupper("yýÿŷẏẙỳỷỹ")) 130 call assert_equal("ZŹŻŽƵẐẔ", toupper("zźżžƶẑẕ")) 131 132 " Test that uppercase diacritics, which should remain unchanged. 133 call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) 134 call assert_equal("BḂḆ", toupper("BḂḆ")) 135 call assert_equal("CÇĆĈĊČ", toupper("CÇĆĈĊČ")) 136 call assert_equal("DĎĐḊḎḐ", toupper("DĎĐḊḎḐ")) 137 call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("EÈÉÊËĒĔĖĘĚẺẼ")) 138 call assert_equal("FḞ ", toupper("FḞ ")) 139 call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("GĜĞĠĢǤǦǴḠ")) 140 call assert_equal("HĤĦḢḦḨ", toupper("HĤĦḢḦḨ")) 141 call assert_equal("IÌÍÎÏĨĪĬĮİǏỈ", toupper("IÌÍÎÏĨĪĬĮİǏỈ")) 142 call assert_equal("JĴ", toupper("JĴ")) 143 call assert_equal("KĶǨḰḴ", toupper("KĶǨḰḴ")) 144 call assert_equal("LĹĻĽĿŁḺ", toupper("LĹĻĽĿŁḺ")) 145 call assert_equal("MḾṀ", toupper("MḾṀ")) 146 call assert_equal("NÑŃŅŇṄṈ", toupper("NÑŃŅŇṄṈ")) 147 call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) 148 call assert_equal("PṔṖ", toupper("PṔṖ")) 149 call assert_equal("Q", toupper("Q")) 150 call assert_equal("RŔŖŘṘṞ", toupper("RŔŖŘṘṞ")) 151 call assert_equal("SŚŜŞŠṠ", toupper("SŚŜŞŠṠ")) 152 call assert_equal("TŢŤŦṪṮ", toupper("TŢŤŦṪṮ")) 153 call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) 154 call assert_equal("VṼ", toupper("VṼ")) 155 call assert_equal("WŴẀẂẄẆ", toupper("WŴẀẂẄẆ")) 156 call assert_equal("XẊẌ", toupper("XẊẌ")) 157 call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ")) 158 call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ")) 159 160 call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ")) 161endfunc 162 163 164