Changeset 331 for EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-string-ext
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-string-ext/mrbgem.rake
r321 r331 3 3 spec.author = 'mruby developers' 4 4 spec.summary = 'String class extension' 5 spec.add_test_dependency 'mruby-enumerator', core: 'mruby-enumerator' 5 6 end -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-string-ext/mrblib/string.rb
r321 r331 1 1 class String 2 3 ## 4 # call-seq: 5 # String.try_convert(obj) -> string or nil 6 # 7 # Try to convert <i>obj</i> into a String, using to_str method. 8 # Returns converted string or nil if <i>obj</i> cannot be converted 9 # for any reason. 10 # 11 # String.try_convert("str") #=> "str" 12 # String.try_convert(/re/) #=> nil 13 # 14 def self.try_convert(obj) 15 if obj.respond_to?(:to_str) 16 obj.to_str 17 else 18 nil 19 end 20 end 2 21 3 22 ## … … 27 46 a = 0 28 47 z = self.size - 1 29 a += 1 while " \f\n\r\t\v".include?(self[a]) and a <= z48 a += 1 while a <= z and " \f\n\r\t\v".include?(self[a]) 30 49 (z >= 0) ? self[a..z] : "" 31 50 end … … 44 63 a = 0 45 64 z = self.size - 1 46 z -= 1 while " \f\n\r\t\v\0".include?(self[z]) and a <= z65 z -= 1 while a <= z and " \f\n\r\t\v\0".include?(self[z]) 47 66 (z >= 0) ? self[a..z] : "" 48 67 end … … 60 79 a = 0 61 80 z = self.size - 1 62 a += 1 while " \f\n\r\t\v".include?(self[a]) and a <= z63 z -= 1 while " \f\n\r\t\v\0".include?(self[z]) and a <= z81 a += 1 while a <= z and " \f\n\r\t\v".include?(self[a]) 82 z -= 1 while a <= z and " \f\n\r\t\v\0".include?(self[z]) 64 83 (z >= 0) ? self[a..z] : "" 65 84 end … … 77 96 # 78 97 def lstrip! 98 raise RuntimeError, "can't modify frozen String" if frozen? 79 99 s = self.lstrip 80 100 (s == self) ? nil : self.replace(s) … … 93 113 # 94 114 def rstrip! 115 raise RuntimeError, "can't modify frozen String" if frozen? 95 116 s = self.rstrip 96 117 (s == self) ? nil : self.replace(s) … … 105 126 # 106 127 def strip! 128 raise RuntimeError, "can't modify frozen String" if frozen? 107 129 s = self.strip 108 130 (s == self) ? nil : self.replace(s) … … 165 187 # 166 188 def slice!(arg1, arg2=nil) 189 raise RuntimeError, "can't modify frozen String" if frozen? 167 190 raise "wrong number of arguments (for 1..2)" if arg1.nil? && arg2.nil? 168 191 … … 189 212 idx = arg1 190 213 idx += self.size if arg1 < 0 191 validated = true if idx >=0 && arg1 < self.size 214 validated = true if idx >=0 && arg1 < self.size 192 215 end 193 216 if validated … … 236 259 # 237 260 def insert(idx, str) 238 pos = idx.to_i 239 pos += self.size + 1 if pos < 0 240 241 raise IndexError, "index #{idx.to_i} out of string" if pos < 0 || pos > self.size 242 243 return self + str if pos == -1 244 return str + self if pos == 0 245 return self[0..pos - 1] + str + self[pos..-1] 261 if idx == -1 262 return self << str 263 elsif idx < 0 264 idx += 1 265 end 266 self[idx, 0] = str 267 self 246 268 end 247 269 … … 258 280 # "hello".ljust(20, '1234') #=> "hello123412341234123" 259 281 def ljust(idx, padstr = ' ') 260 if idx <= self.size 261 return self 262 end 263 newstr = self.dup 264 newstr << padstr 265 while newstr.size <= idx 266 newstr << padstr 267 end 268 return newstr.slice(0,idx) 269 end 270 271 # str.upto(other_str, exclusive=false) {|s| block } -> str 272 # str.upto(other_str, exclusive=false) -> an_enumerator 273 # 274 # Iterates through successive values, starting at <i>str</i> and 275 # ending at <i>other_str</i> inclusive, passing each value in turn to 276 # the block. The <code>String#succ</code> method is used to generate 277 # each value. If optional second argument exclusive is omitted or is false, 278 # the last value will be included; otherwise it will be excluded. 279 # 280 # If no block is given, an enumerator is returned instead. 281 # 282 # "a8".upto("b6") {|s| print s, ' ' } 283 # for s in "a8".."b6" 284 # print s, ' ' 285 # end 286 # 287 # <em>produces:</em> 288 # 289 # a8 a9 b0 b1 b2 b3 b4 b5 b6 290 # a8 a9 b0 b1 b2 b3 b4 b5 b6 291 # 292 # If <i>str</i> and <i>other_str</i> contains only ascii numeric characters, 293 # both are recognized as decimal numbers. In addition, the width of 294 # string (e.g. leading zeros) is handled appropriately. 295 # 296 # "9".upto("11").to_a #=> ["9", "10", "11"] 297 # "25".upto("5").to_a #=> [] 298 # "07".upto("11").to_a #=> ["07", "08", "09", "10", "11"] 299 # 300 def upto(other_str, excl=false, &block) 301 return to_enum :upto, other_str, excl unless block 302 303 str = self 304 n = self.<=>other_str 305 return self if n > 0 || (self == other_str && excl) 306 while true 307 block.call(str) 308 return self if !excl && str == other_str 309 str = str.succ 310 return self if excl && str == other_str 311 end 282 raise ArgumentError, 'zero width padding' if padstr == '' 283 return self if idx <= self.size 284 pad_repetitions = (idx / padstr.length).ceil 285 padding = (padstr * pad_repetitions)[0...(idx - self.length)] 286 self + padding 287 end 288 289 ## 290 # call-seq: 291 # str.rjust(integer, padstr=' ') -> new_str 292 # 293 # If <i>integer</i> is greater than the length of <i>str</i>, returns a new 294 # <code>String</code> of length <i>integer</i> with <i>str</i> right justified 295 # and padded with <i>padstr</i>; otherwise, returns <i>str</i>. 296 # 297 # "hello".rjust(4) #=> "hello" 298 # "hello".rjust(20) #=> " hello" 299 # "hello".rjust(20, '1234') #=> "123412341234123hello" 300 def rjust(idx, padstr = ' ') 301 raise ArgumentError, 'zero width padding' if padstr == '' 302 return self if idx <= self.size 303 pad_repetitions = (idx / padstr.length).ceil 304 padding = (padstr * pad_repetitions)[0...(idx - self.length)] 305 padding + self 312 306 end 313 307 314 308 def chars(&block) 315 309 if block_given? 316 self.split(''). mapdo |i|310 self.split('').each do |i| 317 311 block.call(i) 318 312 end … … 322 316 end 323 317 end 324 alias each_char chars 318 319 def each_char(&block) 320 return to_enum :each_char unless block 321 322 split('').each do |i| 323 block.call(i) 324 end 325 self 326 end 325 327 326 328 def codepoints(&block) … … 328 330 329 331 if block_given? 330 self.split(''). mapdo|x|332 self.split('').each do|x| 331 333 block.call(x.ord) 332 334 end … … 337 339 end 338 340 alias each_codepoint codepoints 341 342 ## 343 # call-seq: 344 # str.prepend(other_str) -> str 345 # 346 # Prepend---Prepend the given string to <i>str</i>. 347 # 348 # a = "world" 349 # a.prepend("hello ") #=> "hello world" 350 # a #=> "hello world" 351 def prepend(arg) 352 self[0, 0] = arg 353 self 354 end 339 355 end -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-string-ext/src/string.c
r321 r331 1 1 #include <string.h> 2 #include "mruby.h"3 #include "mruby/array.h"4 #include "mruby/class.h"5 #include "mruby/string.h"6 #include "mruby/range.h"2 #include <mruby.h> 3 #include <mruby/array.h> 4 #include <mruby/class.h> 5 #include <mruby/string.h> 6 #include <mruby/range.h> 7 7 8 8 static mrb_value … … 24 24 { 25 25 mrb_int pos, byte; 26 long len = RSTRING_LEN(str);26 long len; 27 27 28 28 mrb_get_args(mrb, "ii", &pos, &byte); 29 29 30 len = RSTRING_LEN(str); 30 31 if (pos < -len || len <= pos) 31 32 mrb_raisef(mrb, E_INDEX_ERROR, "index %S is out of array", mrb_fixnum_value(pos)); … … 56 57 57 58 len = RSTRING_LEN(str); 58 if (mrb_range_beg_len(mrb, a1, &beg, &len, len)) { 59 switch (mrb_range_beg_len(mrb, a1, &beg, &len, len, TRUE)) { 60 case 0: /* not range */ 61 break; 62 case 1: /* range */ 59 63 return mrb_str_substr(mrb, str, beg, len); 64 case 2: /* out of range */ 65 mrb_raisef(mrb, E_RANGE_ERROR, "%S out of range", a1); 66 break; 60 67 } 61 68 return mrb_nil_value(); … … 128 135 } 129 136 137 static mrb_value mrb_fixnum_chr(mrb_state *mrb, mrb_value num); 138 130 139 /* 131 140 * call-seq: … … 147 156 { 148 157 mrb_value str; 149 mrb_get_args(mrb, "S", &str); 158 159 mrb_get_args(mrb, "o", &str); 160 if (mrb_fixnum_p(str)) 161 str = mrb_fixnum_chr(mrb, str); 162 else 163 str = mrb_string_type(mrb, str); 150 164 mrb_str_concat(mrb, self, str); 151 165 return self; … … 308 322 mrb_int len; 309 323 mrb_value arg; 310 char *p = RSTRING_PTR(self), *t; 311 char *e = p + RSTRING_LEN(self); 324 char *b = RSTRING_PTR(self); 325 char *p = b, *t; 326 char *e = b + RSTRING_LEN(self); 312 327 313 328 mrb_get_args(mrb, "&", &blk); 314 329 315 330 result = mrb_ary_new(mrb); 316 331 ai = mrb_gc_arena_save(mrb); 317 332 if (!mrb_nil_p(blk)) { 318 333 while (p < e) { … … 323 338 arg = mrb_str_new(mrb, t, len); 324 339 mrb_yield_argv(mrb, blk, 1, &arg); 340 mrb_gc_arena_restore(mrb, ai); 341 if (b != RSTRING_PTR(self)) { 342 ptrdiff_t diff = p - b; 343 b = RSTRING_PTR(self); 344 p = b + diff; 345 } 346 e = b + RSTRING_LEN(self); 325 347 } 326 348 return self; 327 349 } 328 350 while (p < e) { 329 ai = mrb_gc_arena_save(mrb);330 351 t = p; 331 352 while (p < e && *p != '\n') p++; … … 354 375 const char *prepend; 355 376 struct RString *s = mrb_str_ptr(self); 356 size_t l;377 mrb_int l; 357 378 358 379 if (RSTRING_LEN(self) == 0) … … 374 395 e = p + l - 1; 375 396 result = mrb_str_new_lit(mrb, ""); 376 } else { 397 } 398 else { 377 399 // find leading letter of the ascii/number 378 400 b = e; … … 392 414 mrb_str_cat_lit(mrb, result, "\x01"); 393 415 (*e) = 0; 394 } else 416 } 417 else 395 418 (*e)++; 396 419 break; … … 400 423 if (e == b) prepend = "1"; 401 424 *e = '0'; 402 } else if (*e == 'z') { 425 } 426 else if (*e == 'z') { 403 427 if (e == b) prepend = "a"; 404 428 *e = 'a'; 405 } else if (*e == 'Z') { 429 } 430 else if (*e == 'Z') { 406 431 if (e == b) prepend = "A"; 407 432 *e = 'A'; 408 } else { 433 } 434 else { 409 435 (*e)++; 410 436 break; … … 428 454 mrb_str_succ_bang(mrb, str); 429 455 return str; 430 }431 432 /*433 * call-seq:434 * str.prepend(other_str) -> str435 *436 * Prepend---Prepend the given string to <i>str</i>.437 *438 * a = "world"439 * a.prepend("hello ") #=> "hello world"440 * a #=> "hello world"441 */442 static mrb_value443 mrb_str_prepend(mrb_state *mrb, mrb_value self)444 {445 struct RString *s1 = mrb_str_ptr(self), *s2, *temp_s;446 mrb_int len;447 mrb_value other, temp_str;448 449 mrb_get_args(mrb, "S", &other);450 451 mrb_str_modify(mrb, s1);452 if (!mrb_string_p(other)) {453 other = mrb_str_to_str(mrb, other);454 }455 s2 = mrb_str_ptr(other);456 len = RSTR_LEN(s1) + RSTR_LEN(s2);457 temp_str = mrb_str_new(mrb, NULL, RSTR_LEN(s1));458 temp_s = mrb_str_ptr(temp_str);459 memcpy(RSTR_PTR(temp_s), RSTR_PTR(s1), RSTR_LEN(s1));460 if (RSTRING_CAPA(self) < len) {461 mrb_str_resize(mrb, self, len);462 }463 memcpy(RSTR_PTR(s1), RSTR_PTR(s2), RSTR_LEN(s2));464 memcpy(RSTR_PTR(s1) + RSTR_LEN(s2), RSTR_PTR(temp_s), RSTR_LEN(temp_s));465 RSTR_SET_LEN(s1, len);466 RSTR_PTR(s1)[len] = '\0';467 return self;468 456 } 469 457 … … 530 518 if (RSTRING_LEN(str) == 0) 531 519 mrb_raise(mrb, E_ARGUMENT_ERROR, "empty string"); 532 return mrb_fixnum_value( RSTRING_PTR(str)[0]);520 return mrb_fixnum_value((unsigned char)RSTRING_PTR(str)[0]); 533 521 } 534 522 #endif 523 524 static mrb_bool 525 all_digits_p(const char *s, mrb_int len) 526 { 527 while (len-- > 0) { 528 if (!ISDIGIT(*s)) return FALSE; 529 s++; 530 } 531 return TRUE; 532 } 533 534 /* 535 * call-seq: 536 * str.upto(other_str, exclusive=false) {|s| block } -> str 537 * str.upto(other_str, exclusive=false) -> an_enumerator 538 * 539 * Iterates through successive values, starting at <i>str</i> and 540 * ending at <i>other_str</i> inclusive, passing each value in turn to 541 * the block. The <code>String#succ</code> method is used to generate 542 * each value. If optional second argument exclusive is omitted or is false, 543 * the last value will be included; otherwise it will be excluded. 544 * 545 * If no block is given, an enumerator is returned instead. 546 * 547 * "a8".upto("b6") {|s| print s, ' ' } 548 * for s in "a8".."b6" 549 * print s, ' ' 550 * end 551 * 552 * <em>produces:</em> 553 * 554 * a8 a9 b0 b1 b2 b3 b4 b5 b6 555 * a8 a9 b0 b1 b2 b3 b4 b5 b6 556 * 557 * If <i>str</i> and <i>other_str</i> contains only ascii numeric characters, 558 * both are recognized as decimal numbers. In addition, the width of 559 * string (e.g. leading zeros) is handled appropriately. 560 * 561 * "9".upto("11").to_a #=> ["9", "10", "11"] 562 * "25".upto("5").to_a #=> [] 563 * "07".upto("11").to_a #=> ["07", "08", "09", "10", "11"] 564 */ 565 static mrb_value 566 mrb_str_upto(mrb_state *mrb, mrb_value beg) 567 { 568 mrb_value end; 569 mrb_value exclusive = mrb_false_value(); 570 mrb_value block = mrb_nil_value(); 571 mrb_value current, after_end; 572 mrb_int n; 573 mrb_bool excl; 574 575 mrb_get_args(mrb, "o|o&", &end, &exclusive, &block); 576 577 if (mrb_nil_p(block)) { 578 return mrb_funcall(mrb, beg, "to_enum", 3, mrb_symbol_value(mrb_intern_lit(mrb, "upto")), end, exclusive); 579 } 580 end = mrb_string_type(mrb, end); 581 excl = mrb_test(exclusive); 582 583 /* single character */ 584 if (RSTRING_LEN(beg) == 1 && RSTRING_LEN(end) == 1 && 585 ISASCII(RSTRING_PTR(beg)[0]) && ISASCII(RSTRING_PTR(end)[0])) { 586 char c = RSTRING_PTR(beg)[0]; 587 char e = RSTRING_PTR(end)[0]; 588 int ai = mrb_gc_arena_save(mrb); 589 590 if (c > e || (excl && c == e)) return beg; 591 for (;;) { 592 mrb_yield(mrb, block, mrb_str_new(mrb, &c, 1)); 593 mrb_gc_arena_restore(mrb, ai); 594 if (!excl && c == e) break; 595 c++; 596 if (excl && c == e) break; 597 } 598 return beg; 599 } 600 /* both edges are all digits */ 601 if (ISDIGIT(RSTRING_PTR(beg)[0]) && ISDIGIT(RSTRING_PTR(end)[0]) && 602 all_digits_p(RSTRING_PTR(beg), RSTRING_LEN(beg)) && 603 all_digits_p(RSTRING_PTR(end), RSTRING_LEN(end))) { 604 int ai = mrb_gc_arena_save(mrb); 605 mrb_int min_width = RSTRING_LEN(beg); 606 mrb_int max_width = RSTRING_LEN(end); 607 mrb_int bi = mrb_int(mrb, mrb_str_to_inum(mrb, beg, 10, FALSE)); 608 mrb_int ei = mrb_int(mrb, mrb_str_to_inum(mrb, end, 10, FALSE)); 609 mrb_value str = mrb_str_new(mrb, NULL, max_width); 610 char *buf = RSTRING_PTR(str); 611 612 while (bi <= ei) { 613 if (excl && bi == ei) break; 614 snprintf(buf, max_width+1, "%.*" MRB_PRId, (int)min_width, bi); 615 mrb_yield(mrb, block, mrb_str_new(mrb, buf, strlen(buf))); 616 mrb_gc_arena_restore(mrb, ai); 617 bi++; 618 } 619 620 return beg; 621 } 622 /* normal case */ 623 n = mrb_int(mrb, mrb_funcall(mrb, beg, "<=>", 1, end)); 624 if (n > 0 || (excl && n == 0)) return beg; 625 626 after_end = mrb_funcall(mrb, end, "succ", 0); 627 current = mrb_str_dup(mrb, beg); 628 while (!mrb_str_equal(mrb, current, after_end)) { 629 int ai = mrb_gc_arena_save(mrb); 630 mrb_value next = mrb_nil_value(); 631 if (excl || !mrb_str_equal(mrb, current, end)) 632 next = mrb_funcall(mrb, current, "succ", 0); 633 mrb_yield(mrb, block, current); 634 if (mrb_nil_p(next)) break; 635 current = mrb_str_to_str(mrb, next); 636 if (excl && mrb_str_equal(mrb, current, end)) break; 637 if (RSTRING_LEN(current) > RSTRING_LEN(end) || RSTRING_LEN(current) == 0) 638 break; 639 mrb_gc_arena_restore(mrb, ai); 640 } 641 642 return beg; 643 } 535 644 536 645 void … … 555 664 mrb_define_method(mrb, s, "succ", mrb_str_succ, MRB_ARGS_NONE()); 556 665 mrb_define_method(mrb, s, "succ!", mrb_str_succ_bang, MRB_ARGS_NONE()); 557 mrb_define_method(mrb, s, "prepend", mrb_str_prepend, MRB_ARGS_REQ(1));558 666 mrb_alias_method(mrb, s, mrb_intern_lit(mrb, "next"), mrb_intern_lit(mrb, "succ")); 559 667 mrb_alias_method(mrb, s, mrb_intern_lit(mrb, "next!"), mrb_intern_lit(mrb, "succ!")); 560 668 mrb_define_method(mrb, s, "ord", mrb_str_ord, MRB_ARGS_NONE()); 669 mrb_define_method(mrb, s, "upto", mrb_str_upto, MRB_ARGS_ANY()); 561 670 562 671 mrb_define_method(mrb, mrb->fixnum_class, "chr", mrb_fixnum_chr, MRB_ARGS_NONE()); -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-string-ext/test/string.rb
r321 r331 3 3 4 4 UTF8STRING = ("\343\201\202".size == 1) 5 6 assert('String.try_convert') do 7 assert_nil String.try_convert(nil) 8 assert_nil String.try_convert(:foo) 9 assert_equal "", String.try_convert("") 10 assert_equal "1,2,3", String.try_convert("1,2,3") 11 end 5 12 6 13 assert('String#getbyte') do … … 22 29 assert_equal(h, str1.getbyte(0)) 23 30 assert_equal("Hello", str1) 31 end 32 33 assert("String#setbyte raises IndexError if arg conversion resizes String") do 34 $s = "01234\n" 35 class Tmp 36 def to_i 37 $s.chomp! '' 38 95 39 end 40 end 41 tmp = Tmp.new 42 assert_raise(IndexError) { $s.setbyte(5, tmp) } 24 43 end 25 44 … … 104 123 105 124 assert('String#concat') do 106 s = "Hello " 107 s.concat "World!" 108 t = "Hello " 109 t << "World!" 110 assert_equal "Hello World!", t 111 assert_equal "Hello World!", s 125 assert_equal "Hello World!", "Hello " << "World" << 33 126 assert_equal "Hello World!", "Hello ".concat("World").concat(33) 127 128 o = Object.new 129 def o.to_str 130 "to_str" 131 end 132 assert_equal "hi to_str", "hi " << o 133 134 assert_raise(TypeError) { "".concat(Object.new) } 112 135 end 113 136 … … 400 423 assert_raise(IndexError) { "abcd".insert(5, 'X') } 401 424 assert_raise(IndexError) { "abcd".insert(-6, 'X') } 425 426 a = "abcd" 427 a.insert(0, 'X') 428 assert_equal "Xabcd", a 402 429 end 403 430 … … 411 438 assert_equal "hello", "hello".ljust(4) 412 439 assert_equal "hello ", "hello".ljust(20) 440 assert_equal 20, "hello".ljust(20).length 413 441 assert_equal "hello123412341234123", "hello".ljust(20, '1234') 414 442 assert_equal "hello", "hello".ljust(-3) 415 443 end 416 444 445 assert('String#rjust') do 446 assert_equal "hello", "hello".rjust(4) 447 assert_equal " hello", "hello".rjust(20) 448 assert_equal 20, "hello".rjust(20).length 449 assert_equal "123412341234123hello", "hello".rjust(20, '1234') 450 assert_equal "hello", "hello".rjust(-3) 451 end 452 453 if UTF8STRING 454 assert('String#ljust with UTF8') do 455 assert_equal "helloん ", "helloん".ljust(20) 456 assert_equal "helloó ", "helloó".ljust(34) 457 assert_equal 34, "helloó".ljust(34).length 458 assert_equal "helloんんんんんんんんんんんんんん", "hello".ljust(19, 'ん') 459 assert_equal "helloんんんんんんんんんんんんんんん", "hello".ljust(20, 'ん') 460 end 461 462 assert('String#rjust with UTF8') do 463 assert_equal " helloん", "helloん".rjust(20) 464 assert_equal " helloó", "helloó".rjust(34) 465 # assert_equal 34, "helloó".rjust(34).length 466 assert_equal "んんんんんんんんんんんんんんhello", "hello".rjust(19, 'ん') 467 assert_equal "んんんんんんんんんんんんんんんhello", "hello".rjust(20, 'ん') 468 end 469 470 assert('UTF8 byte counting') do 471 ret = ' ' 472 ret[-6..-1] = "helloó" 473 assert_equal 34, ret.length 474 end 475 end 476 477 assert('String#ljust should not change string') do 478 a = "hello" 479 a.ljust(20) 480 assert_equal "hello", a 481 end 482 483 assert('String#rjust should not change string') do 484 a = "hello" 485 a.rjust(20) 486 assert_equal "hello", a 487 end 488 489 assert('String#ljust should raise on zero width padding') do 490 assert_raise(ArgumentError) { "foo".ljust(10, '') } 491 end 492 493 assert('String#rjust should raise on zero width padding') do 494 assert_raise(ArgumentError) { "foo".rjust(10, '') } 495 end 496 417 497 assert('String#upto') do 498 assert_equal %w(a8 a9 b0 b1 b2 b3 b4 b5 b6), "a8".upto("b6").to_a 499 assert_equal ["9", "10", "11"], "9".upto("11").to_a 500 assert_equal [], "25".upto("5").to_a 501 assert_equal ["07", "08", "09", "10", "11"], "07".upto("11").to_a 502 503 if UTF8STRING 504 assert_equal ["あ", "ぃ", "い", "ぅ", "う", "ぇ", "え", "ぉ", "お"], "あ".upto("お").to_a 505 end 506 507 assert_equal ["9", ":", ";", "<", "=", ">", "?", "@", "A"], "9".upto("A").to_a 508 418 509 a = "aa" 419 510 start = "aa" … … 475 566 }) 476 567 assert_equal(2, count) 568 569 assert_raise(TypeError) { "a".upto(:c) {} } 477 570 end 478 571 … … 480 573 got = "hello!".split('').map {|x| x.ord} 481 574 expect = [104, 101, 108, 108, 111, 33] 575 unless UTF8STRING 576 got << "\xff".ord 577 expect << 0xff 578 end 482 579 assert_equal expect, got 483 580 end
Note:
See TracChangeset
for help on using the changeset viewer.