aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_string.rb
Commit message (Collapse)AuthorAgeFilesLines
* string.c: fix memory leak in rb_str_change_terminator_length()work2Kazuki Yamaguchi2017-11-121-0/+11
| | | | | str_make_independent_expand() cannot be used for a String that has its own buffer.
* Fix a target method of a testyui-knk2017-10-221-1/+1
| | | | | | | | | * test/ruby/test_string.rb (test_delete): I guess this line should be a test case which asserts coderange is handled correctly when a result of String#delete has non-ASCII characters. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Improve performance of string interpolationnobu2017-10-211-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch will add pre-allocation in string interpolation. By this, unecessary capacity resizing is avoided. For small strings, optimized `rb_str_resurrect` operation is faster, so pre-allocation is done only when concatenated strings are large. `MIN_PRE_ALLOC_SIZE` was decided by experimenting with local machine (x86_64-apple-darwin 16.5.0, Apple LLVM version 8.1.0 (clang - 802.0.42)). String interpolation will be faster around 72% when large string is created. * Before ``` Calculating ------------------------------------- Large string interpolation 1.276M (± 5.9%) i/s - 6.358M in 5.002022s Small string interpolation 5.156M (± 5.5%) i/s - 25.728M in 5.005731s ``` * After ``` Calculating ------------------------------------- Large string interpolation 2.201M (± 5.8%) i/s - 11.063M in 5.043724s Small string interpolation 5.192M (± 5.7%) i/s - 25.971M in 5.020516s ``` * Test code ```ruby require 'benchmark/ips' Benchmark.ips do |x| x.report "Large string interpolation" do |t| a = "Hellooooooooooooooooooooooooooooooooooooooooooooooooooo" b = "Wooooooooooooooooooooooooooooooooooooooooooooooooooorld" t.times do "#{a}, #{b}!" end end x.report "Small string interpolation" do |t| a = "Hello" b = "World" t.times do "#{a}, #{b}!" end end end ``` [Fix GH-1626] From: Nao Minami <south37777@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [Feature #13712] String#start_with? supports regexpnaruse2017-10-211-0/+5
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: fix ASCII-only on succnobu2017-09-301-0/+5
| | | | | | | | * string.c (str_succ): clear coderange cache when no alpha-numeric character case, carried part may become ASCII-only. [ruby-core:83062] [Bug #13952] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: ASCII-incompatible is not ASCII onlynobu2017-09-291-1/+6
| | | | | | | * string.c (tr_trans): ASCII-incompatible encoding strings cannot be ASCII-only even if valid. [ruby-core:83056] [Bug #13950] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dup String#split return valuenobu2017-09-231-0/+5
| | | | | | | | | * string.c (rb_str_split): return duplicated receiver, when no splits. patched by tompng (tomoya ishida) in [ruby-core:82911], and the test case by Seiei Miyagi <hanachin@gmail.com>. [Bug#13925] [Fix GH-1705] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dup String#rpartition return valuenobu2017-09-231-0/+5
| | | | | | | | | * string.c (rb_str_rpartition): return duplicated receiver, when no splits. [ruby-core:82911] [Bug#13925] Author: Seiei Miyagi <hanachin@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dup String#partition return valuenobu2017-09-231-1/+6
| | | | | | | | | * string.c (rb_str_partition): return duplicated receiver, when no splits. [ruby-core:82911] [Bug#13925] Author: Seiei Miyagi <hanachin@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: grapheme clusters on frozen stringnobu2017-09-041-0/+2
| | | | | | | * string.c (rb_str_enumerate_grapheme_clusters): enumerate on shared frozen string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: enumerator_wantarraynobu2017-09-031-4/+35
| | | | | | | * string.c (enumerator_wantarray): show warnings at method functions for proper method names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: fix for non-Unicode encodingsnobu2017-09-031-0/+2
| | | | | | | * string.c (rb_str_enumerate_grapheme_clusters): should enumerate chars for non-Unicode encodings. [Feature #13780] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* String#each_grapheme_cluster and String#grapheme_clustersnaruse2017-08-311-0/+40
| | | | | | added to enumerate grapheme clusters [Feature #13780] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Suppress warning: shadowing outer local variable - klassnaruse2017-08-121-6/+6
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59579 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: add String#delete_suffix and String#delete_suffix!sonots2017-07-201-0/+145
| | | | | | | | | | | | | | to remove trailing suffix [Feature #13665] [Fix GH-1661] * string.c (rb_str_delete_suffix_bang): add a new method to remove suffix destuctively. * string.c (rb_str_delete_suffix): add a new method to remove suffix non-destuctively. * test/ruby/test_string.rb: add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* revert r59359, r59356, r59355, r59354normal2017-07-191-6/+0
| | | | | | | These caused numerous CI failures I haven't been able to reproduce [ruby-core:82102] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix typonobu2017-07-181-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* descriptive asssertionsnobu2017-07-181-10/+10
| | | | | | | * test/ruby/test_string.rb (test_uplus_minus): prefer more descriptive asssertions than assert_equal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string: preserve taint flag with String#-@ (uminus)normal2017-07-181-0/+5
| | | | | | | | | * string.c (tainted_fstr_update): move up (rb_fstring): support registering tainted strings (register_fstring_tainted): extract from rb_fstring_existing0 (rb_tainted_fstring_existing): use register_fstring_tainted instead git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/ruby/test_string.rb: ensure we do not have tainted stringsnormal2017-07-181-0/+2
| | | | | | | Trying to figure out [ruby-core:82092] cf. https://gist.github.com/e2c899c453f3f66e7934095c32505486 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/ruby/test_string.rb: add tests to chomp substrsonots2017-06-211-0/+72
| | | | | | | | | * test/ruby/test_string.rb (TestString#test_chomp): add tests to chomp substr * test/ruby/test_string.rb (TestString#test_chomp!): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: add String#delete_prefix and String#delete_prefix!sonots2017-06-211-0/+95
| | | | | | | | | | | | | | to remove leading substr [Feature #12694] [fix GH-1632] * string.c (rb_str_delete_prefix_bang): add a new method to remove prefix destuctively. * string.c (rb_str_delete_prefix): add a new method to remove prefix non-destuctively. * test/ruby/test_string.rb: add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: check just before modificationnobu2017-06-181-0/+8
| | | | | | | | * string.c (rb_str_chomp_bang): check if modifiable after checking an argument and just before modification, as it can get frozen during the argument conversion to String. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test_string.rb: chomp! frozen stringnobu2017-06-181-0/+3
| | | | | | | * test/ruby/test_string.rb (TestString#test_chomp): should raise if frozen. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: fix String#crypt leak introduced in r58866normal2017-05-241-0/+4
| | | | | | * string.c (rb_str_crypt): define LARGE_CRYPT_DATA when allocating git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: fix String#{casecmp,casecmp?} for non-string argumentsstomar2017-05-211-0/+14
| | | | | | | | | | | | * string.c: make String#{casecmp,casecmp?} return nil for non-string arguments instead of raising a TypeError. * test/ruby/test_string.rb: add tests. Reported by Marcus Stollsteimer. Based on a patch by Shingo Morita. [ruby-core:80145] [Bug #13312] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test_string.rb,test_symbol.rb: add some testsstomar2017-05-211-0/+3
| | | | | | | * test/ruby/test_string.rb: add more test cases for String#casecmp. * test/ruby/test_symbol.rb: ditto for Symbol#{casecmp,casecmp?}. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Rename RbConfig::Limits as RbConfig::LIMITSnobu2017-04-061-1/+1
| | | | | | | | * template/limits.c.tmpl (Init_limits): rename RbConfig::Limits as RbConfig::LIMITS, constants other than class or module are all uppercase with underscores by convention. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: $; is a GC-rootnobu2017-03-131-0/+11
| | | | | | | * string.c (Init_String): $; must be a GC-root, not to be collected. [ruby-core:79582] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: negation of LONG_MINnobu2017-03-071-0/+2
| | | | | | | * string.c (rb_str_update): do not use negation of LONG_MIN, which is negative too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* NEWS: document String#-@ changenormal2017-02-251-0/+2
| | | | | | | * test/ruby/test_string.rb (test_uplus_minus): test deduplication [ruby-core:79747] [Feature #13077] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: rindex(//) should set $~.shugo2017-01-191-0/+3
| | | | | | This seems a bug introduced by r520 (1.4.0). [ruby-core:79110] [Bug #13135] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: CRLF in paragraph modenobu2016-12-251-0/+10
| | | | | | | * string.c (rb_str_enumerate_lines): allow CRLF to separate paragraphs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: consistent paragraph mode with IOnobu2016-12-251-6/+6
| | | | | | | | * string.c (rb_str_enumerate_lines): in paragraph mode, do not include newlines which separate paragraphs, so that it will be consistent with IO#each_line. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* re.c: non-regexp name referencenobu2016-12-171-0/+4
| | | | | | | * re.c (rb_reg_regsub): other than regexp has no name references. [ruby-core:78686] [Bug #13042] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix chomping newline only linenobu2016-12-161-0/+12
| | | | | | | | | * string.c (chomp_newline): fix chomping newline only line. rb_enc_prev_char return NULL if no previous character and must not call rb_enc_ascget on it. a patch by Ary Borenszweig <asterite AT gmail.com> at [ruby-core:78666]. [Bug #13037] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* String#match? and Symbol#match?nobu2016-12-121-0/+44
| | | | | | | | * string.c (rb_str_match_m_p): inverse of Regexp#match?. based on the patch by Herwin Weststrate <herwin@snt.utwente.nl>. [Fix GH-1483] [Feature #12898] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* switching hash removalnobu2016-12-061-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | * st.h (struct st_hash_type): Remove strong_hash. (struct st_table): Remove inside_rebuild_p and curr_hash. * st.c (do_hash): Use type->hash instead of curr_hash. (make_tab_empty): Remove setting up curr_hash. (st_init_table_with_size): Remove setting up inside_rebuild_p. (rebuild_table): Remove clearing inside_rebuild_p. (reset_entry_hashes, HIT_THRESHOULD_FOR_STRONG_HASH): Remove code recognizing a denial attack and switching to strong hash. * hash.c (rb_dbl_long_hash, rb_objid_hash, rb_ident_hash): Use rb_hash_start to randomize the hash. (str_seed): Remove. (any_hash): Remove strong_p and use always rb_str_hash for strings. (any_hash_weak, rb_any_hash_weak): Remove. (st_hash_type objhash): Remove rb_any_hash_weak. based on the patch by Vladimir N Makarov <vmakarov@redhat.com> at [ruby-core:78490]. [Bug #13002] * test/ruby/test_hash.rb (test_wrapper): objects other than special constants should be able to be wrapped. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: chomp optionnobu2016-12-031-0/+29
| | | | | | * string.c (rb_str_enumerate_lines): implement chomp option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/ruby/test_string.rb: ensure restoring $/nobu2016-12-021-0/+7
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* implement String/Symbol#casecmp? including Unicode case foldingduerst2016-11-281-0/+7
| | | | | | | | | | | * string.c: Implement String#casecmp? and Symbol#casecmp? by using String#downcase :fold for Unicode case folding. This does not include options such as :turkic, because these currently cannot be combined with the :fold option. This implements feature #12786. * test/ruby/test_string.rb/test_symbol.rb: Tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* multiple argumentsnobu2016-08-271-1/+6
| | | | | | | | * array.c (rb_ary_concat_multi): take multiple arguments. based on the patch by Satoru Horie. [Feature #12333] * string.c (rb_str_concat_multi, rb_str_prepend_multi): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: rb_fs_setternobu2016-08-231-4/+5
| | | | | | | * string.c (rb_fs_setter): check and convert $; value at assignment. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: $; name in error messagenobu2016-08-221-1/+8
| | | | | | | * string.c (rb_str_split_m): show $; name in error message when it is a wrong object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * string.c (String#dump): Change escaping of non-ASCII characters induerst2016-07-221-0/+12
| | | | | | | | | UTF-8 to use upper-case four-digit hexadecimal escapes without braces where possible [Feature #12419]. * test/ruby/test_string.rb (test_dump): Add tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* string.c: fix rb_str_initnobu2016-02-171-0/+18
| | | | | | | * string.c (rb_str_init): fix segfault and memory leak, consider wide char encoding terminator. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Additional fix and tests for r53851naruse2016-02-171-0/+11
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * string.c (rb_str_init): introduce String.new(capacity: size)naruse2016-02-171-0/+12
| | | | | | [Feature #12024] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/ruby/test_string.rb: added testcase for next!, succ and succ!hsbt2016-01-251-0/+18
| | | | | | [fix GH-1213] Patch by @K0mAtoru git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/ruby/test_string.rb: Added extra testcase for test_rstrip_banghsbt2016-01-181-0/+8
| | | | | | and test_lstrip_bang. [fix GH-1178] Patch by @Matrixbirds git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e