Permalink
Browse files

Merge branch 'master' into iij

Conflicts:
	mrblib/string.rb
	test/t/string.rb
  • Loading branch information...
2 parents ad67688 + 8578cd6 commit 9471c3f704aba11f2f5a17a9e54b03ed84862388 @akiray03 akiray03 committed Feb 14, 2013
Showing with 143 additions and 117 deletions.
  1. +26 −26 doc/compile/README.md
  2. +14 −16 mrblib/string.rb
  3. +103 −75 test/t/string.rb
View
@@ -19,7 +19,7 @@ Optional:
## Usage
-Inside of the root directory of the mruby source exist a file
+Inside of the root directory of the mruby source a file exists
called *build_config.rb*. This file contains the build configuration
of mruby and looks like this for example:
@@ -29,21 +29,21 @@ of mruby and looks like this for example:
All tools necessary to compile mruby can be set or modified here. In case
you want to maintain an additional *build_config.rb* you can define a
-customized path using the *$MRUBY_CONFIG* environment variable.
+customized path using the *$MRUBY_CONFIG* environment variable.
To compile just call ```./minirake``` inside of the mruby source root. To
generate and execute the test tools call ```./minirake test```. To clean
all build files call ```./minirake clean```.
## Build Configuration
-Inside of the *build_config.rb* the following options can be configurated
+Inside of the *build_config.rb* the following options can be configured
based on your environment.
### Toolchains
-The mruby build system contains already a set of toolchain templates which
-configurates the build environment for specific compiler infrastructures.
+The mruby build system already contains a set of toolchain templates which
+configure the build environment for specific compiler infrastructures.
#### GCC
@@ -79,7 +79,7 @@ It is possible to select which tools should be compiled during the compilation
process. The following tools can be selected:
* mrbc (mruby compiler)
* mruby (mruby interpreter)
-* mirb (mruby interactive shell
+* mirb (mruby interactive shell)
To select all define an array in ```conf.bins```:
@@ -182,7 +182,7 @@ If you want mrbtest.a only, You should set ```conf.build_mrbtest_lib_only```
## Cross-Compilation
mruby can also be cross-compiled from one platform to another. To
-achive this the *build_config.rb* needs to contain an instance of
+achieve this the *build_config.rb* needs to contain an instance of
```MRuby::CrossBuild```. This instance defines the compilation
tools and flags for the target platform. An example could look
like this:
@@ -226,21 +226,21 @@ root directory. The structure of this directory will look like this:
The compilation workflow will look like this:
* compile all files under *src* (object files will be stored
-in *build/host/src*
+in *build/host/src*)
* generate parser grammar out of *src/parse.y* (generated
-result will be stored in *build/host/src/y.tab.c*
+result will be stored in *build/host/src/y.tab.c*)
* compile *build/host/src/y.tab.c* to *build/host/src/y.tab.o*
* create *build/host/lib/libmruby_core.a* out of all object files (C only)
-* create ```build/host/bin/mrbc``` by compile *tools/mrbc/mrbc.c* and
-link with *build/host/lib/libmruby_core.a*
+* create ```build/host/bin/mrbc``` by compiling *tools/mrbc/mrbc.c* and
+linking with *build/host/lib/libmruby_core.a*
* create *build/host/mrblib/mrblib.c* by compiling all *.rb files
under *mrblib* with ```build/host/bin/mrbc```
* compile *build/host/mrblib/mrblib.c* to *build/host/mrblib/mrblib.o*
* create *build/host/lib/libmruby.a* out of all object files (C and Ruby)
-* create ```build/host/bin/mruby``` by compile *tools/mruby/mruby.c* and
-link with *build/host/lib/libmruby.a*
-* create ```build/host/bin/mirb``` by compile *tools/mirb/mirb.c* and
-link with *build/host/lib/libmruby.a*
+* create ```build/host/bin/mruby``` by compiling *tools/mruby/mruby.c* and
+linking with *build/host/lib/libmruby.a*
+* create ```build/host/bin/mirb``` by compiling *tools/mirb/mirb.c* and
+linking with *build/host/lib/libmruby.a*
```
_____ _____ ______ ____ ____ _____ _____ ____
@@ -301,23 +301,23 @@ build direcotry.
The cross compilation workflow starts in the same way as the normal
compilation by compiling all *native* libraries and binaries.
-Aftwards the cross compilation process proceeds like this:
+Afterwards the cross compilation process proceeds like this:
* cross-compile all files under *src* (object files will be stored
-in *build/i386/src*
+in *build/i386/src*)
* generate parser grammar out of *src/parse.y* (generated
-result will be stored in *build/i386/src/y.tab.c*
-* cross-compile *build/i386/src/y.tab.c* to *build/i386/src/y.tab.o*
+result will be stored in *build/i386/src/y.tab.c*)
+* cross-compile *build/i386/src/y.tab.c* to *build/i386/src/y.tab.o*
* create *build/i386/mrblib/mrblib.c* by compiling all *.rb files
under *mrblib* with the native ```build/host/bin/mrbc```
* cross-compile *build/host/mrblib/mrblib.c* to *build/host/mrblib/mrblib.o*
* create *build/i386/lib/libmruby.a* out of all object files (C and Ruby)
-* create ```build/i386/bin/mruby``` by cross-compile *tools/mruby/mruby.c* and
-link with *build/i386/lib/libmruby.a*
-* create ```build/i386/bin/mirb``` by cross-compile *tools/mirb/mirb.c* and
-link with *build/i386/lib/libmruby.a*
+* create ```build/i386/bin/mruby``` by cross-compiling *tools/mruby/mruby.c* and
+linking with *build/i386/lib/libmruby.a*
+* create ```build/i386/bin/mirb``` by cross-compiling *tools/mirb/mirb.c* and
+linking with *build/i386/lib/libmruby.a*
* create *build/i386/lib/libmruby_core.a* out of all object files (C only)
-* create ```build/i386/bin/mrbc``` by cross-compile *tools/mrbc/mrbc.c* and
-link with *build/i386/lib/libmruby_core.a*
+* create ```build/i386/bin/mrbc``` by cross-compiling *tools/mrbc/mrbc.c* and
+linking with *build/i386/lib/libmruby_core.a*
```
_______________________________________________________________
@@ -345,4 +345,4 @@ mruby's build process includes a test environment. In case you start the testing
of mruby, a native binary called ```mrbtest``` will be generated and executed.
This binary contains all test cases which are defined under *test/t*. In case
of a cross-compilation an additional cross-compiled *mrbtest* binary is
-generated. This binary you can copy and run on your target system.
+generated. You can copy this binary and run on your target system.
View
@@ -28,15 +28,14 @@ def each_line(&block)
#
# ISO 15.2.10.5.18
def gsub(*args, &block)
- unless (args.size == 1 && block) || args.size == 2
- raise ArgumentError, "wrong number of arguments"
- end
-
- ### *** TODO *** ###
- unless Object.const_defined?(:Regexp)
- raise NotImplementedError, "gsub not available (yet)"
+ if Object.const_defined?(:Regexp) && args[0].is_a?(Regexp)
+ _gsub(*args, &block)
+ elsif args.size == 2
+ split(args[0]).join(args[1])
+ elsif args.size == 1 && block
+ split(args[0]).join(block.call(args[0]))
else
- self._gsub(*args, &block)
+ raise ArgumentError, "wrong number of arguments"
end
end
@@ -80,15 +79,14 @@ def scan(reg, &block)
#
# ISO 15.2.10.5.36
def sub(*args, &block)
- unless (args.size == 1 && block) || args.size == 2
- raise ArgumentError, "wrong number of arguments"
- end
-
- ### *** TODO *** ###
- unless Object.const_defined?(:Regexp)
- raise NotImplementedError, "sub not available (yet)"
+ if Object.const_defined?(:Regexp) && args[0].is_a?(Regexp)
+ _sub(*args, &block)
+ elsif args.size == 2
+ split(args[0], 2).join(args[1])
+ elsif args.size == 1 && block
+ split(args[0], 2).join(block.call(args[0]))
else
- self._sub(*args, &block)
+ raise ArgumentError, "wrong number of arguments"
end
end
View
@@ -193,36 +193,50 @@
end
if Object.const_defined?(:Regexp)
-# TODO ATM broken assert('String#gsub', '15.2.10.5.18') do
-assert('String#gsub', '15.2.10.5.18') do
- re = Regexp.compile('def')
- result1 = 'abcdefg'.gsub(re, '!!')
- re = Regexp.compile('b')
- result2 = 'abcabc'.gsub(re, '<<\&>>')
- re = Regexp.compile('x+(b+)')
- result3 = 'xxbbxbb'.gsub(re, 'X<<\1>>')
- result4 = '2.5'.gsub('.', ',')
+ # TODO ATM broken assert('String#gsub', '15.2.10.5.18') do
+ assert('String#gsub with Regexp', '15.2.10.5.18') do
+ re = Regexp.compile('def')
+ result1 = 'abcdefg'.gsub(re, '!!')
+ re = Regexp.compile('b')
+ result2 = 'abcabc'.gsub(re, '<<\&>>')
+ re = Regexp.compile('x+(b+)')
+ result3 = 'xxbbxbb'.gsub(re, 'X<<\1>>')
+ result4 = '2.5'.gsub('.', ',')
+
+ result1 == "abc!!g" and
+ result2 == "a<<b>>ca<<b>>c" and
+ result3 == "X<<bb>>X<<bb>>" and
+ result4 == "2,5"
+ end
+
+ # TODO ATM broken assert('String#gsub!', '15.2.10.5.19') do
+ assert('String#gsub! with Regexp', '15.2.10.5.19') do
+ result1 = "String-String"
+ re = Regexp.compile('in.')
+ result1.gsub!(re, "!!")
+
+ result2 = "String-String"
+ re = Regexp.compile('in.')
+ result2.gsub!(re, '<<\&>>')
+
+ result1 == "Str!!-Str!!" and
+ result2 == "Str<<ing>>-Str<<ing>>"
+ end
+end # END: Object.const_defined?(:Regexp)
- result1 == "abc!!g" and
- result2 == "a<<b>>ca<<b>>c" and
- result3 == "X<<bb>>X<<bb>>" and
- result4 == "2,5"
+assert('String#gsub', '15.2.10.5.18') do
+ 'abcabc'.gsub('b', 'B') == 'aBcaBc' && 'abcabc'.gsub('b') { |w| w.capitalize } == 'aBcaBc'
end
-# TODO ATM broken assert('String#gsub!', '15.2.10.5.19') do
assert('String#gsub!', '15.2.10.5.19') do
- result1 = "String-String"
- re = Regexp.compile('in.')
- result1.gsub!(re, "!!")
+ a = 'abcabc'
+ a.gsub!('b', 'B')
- result2 = "String-String"
- re = Regexp.compile('in.')
- result2.gsub!(re, '<<\&>>')
+ b = 'abcabc'
+ b.gsub!('b') { |w| w.capitalize }
- result1 == "Str!!-Str!!" and
- result2 == "Str<<ing>>-Str<<ing>>"
+ a == 'aBcaBc' && b == 'aBcaBc'
end
-end # END: Object.const_defined?(:Regexp)
assert('String#hash', '15.2.10.5.20') do
a = 'abc'
@@ -291,22 +305,22 @@
end
if Object.const_defined?(:Regexp)
-# TODO Broken ATM assert('String#scan', '15.2.10.5.32') do
-assert('String#scan', '15.2.10.5.32') do
- re = Regexp.compile('..')
- result1 = "foobar".scan(re)
- re = Regexp.compile('ba.')
- result2 = "foobarbazfoobarbazz".scan(re)
- re = Regexp.compile('(.)')
- result3 = "foobar".scan(re)
- re = Regexp.compile('(ba)(.)')
- result4 = "foobarbazfoobarbaz".scan(re)
-
- result1 == ["fo", "ob", "ar"] and
- result2 == ["bar", "baz", "bar", "baz"] and
- result3 == [["f"], ["o"], ["o"], ["b"], ["a"], ["r"]] and
- result4 == [["ba", "r"], ["ba", "z"], ["ba", "r"], ["ba", "z"]]
-end
+ # TODO Broken ATM assert('String#scan', '15.2.10.5.32') do
+ assert('String#scan', '15.2.10.5.32') do
+ re = Regexp.compile('..')
+ result1 = "foobar".scan(re)
+ re = Regexp.compile('ba.')
+ result2 = "foobarbazfoobarbazz".scan(re)
+ re = Regexp.compile('(.)')
+ result3 = "foobar".scan(re)
+ re = Regexp.compile('(ba)(.)')
+ result4 = "foobarbazfoobarbaz".scan(re)
+
+ result1 == ["fo", "ob", "ar"] and
+ result2 == ["bar", "baz", "bar", "baz"] and
+ result3 == [["f"], ["o"], ["o"], ["b"], ["a"], ["r"]] and
+ result4 == [["ba", "r"], ["ba", "z"], ["ba", "r"], ["ba", "z"]]
+ end
end
assert('String#size', '15.2.10.5.33') do
@@ -365,21 +379,21 @@
end
if Object.const_defined?(:Regexp)
-assert('String#split', '15.2.10.5.35') do
- ''.split(//) == [] and
- ''.split(/x/) == [] and
- 'abc'.split(//) == ['a', 'b', 'c'] and
- 'abc'.split(/,/) == ['abc'] and
- 'a1b23c45'.split(/\d/) == ['a', 'b', '', 'c'] and
- 'a1b23c45'.split(/\d/, 0) == ['a', 'b', '', 'c'] and
- 'a1b23c45'.split(/\d/, 1) == ['a1b23c45'] and
- 'a1b23c45'.split(/\d/, 4) == ['a', 'b', '', 'c45'] and
- 'a1b23c45'.split(/\d/, -4) == ['a', 'b', '', 'c', '', ''] and
- 'abc'.split(//, 2) == ['a', 'bc'] and
- 'a bc'.split(/\s*/) == ['a', 'b', 'c'] and
- ' abc abc abc'.split(/ /) == ['', 'abc', '', 'abc', 'abc'] and
- '1, 2.34,56, 7'.split(/,\s*/) == ['1', '2.34', '56', '7']
-end
+ assert('String#split', '15.2.10.5.35') do
+ ''.split(//) == [] and
+ ''.split(/x/) == [] and
+ 'abc'.split(//) == ['a', 'b', 'c'] and
+ 'abc'.split(/,/) == ['abc'] and
+ 'a1b23c45'.split(/\d/) == ['a', 'b', '', 'c'] and
+ 'a1b23c45'.split(/\d/, 0) == ['a', 'b', '', 'c'] and
+ 'a1b23c45'.split(/\d/, 1) == ['a1b23c45'] and
+ 'a1b23c45'.split(/\d/, 4) == ['a', 'b', '', 'c45'] and
+ 'a1b23c45'.split(/\d/, -4) == ['a', 'b', '', 'c', '', ''] and
+ 'abc'.split(//, 2) == ['a', 'bc'] and
+ 'a bc'.split(/\s*/) == ['a', 'b', 'c'] and
+ ' abc abc abc'.split(/ /) == ['', 'abc', '', 'abc', 'abc'] and
+ '1, 2.34,56, 7'.split(/,\s*/) == ['1', '2.34', '56', '7']
+ end
end
assert('String#split with non-Regexp separator') do
@@ -412,34 +426,48 @@
end
if Object.const_defined?(:Regexp)
-# TODO ATM broken assert('String#sub', '15.2.10.5.36') do
-assert('String#sub', '15.2.10.5.36') do
- re = Regexp.compile('def')
- result1 = 'abcdefg'.sub(re, '!!')
- re = Regexp.compile('b')
- result2 = 'abcabc'.sub(re, '<<\&>>')
- re = Regexp.compile('x+(b+)')
- result3 = 'xbbxbb'.sub(re, 'X<<\1>>')
+ # TODO ATM broken assert('String#sub', '15.2.10.5.36') do
+ assert('String#sub with Regexp', '15.2.10.5.36') do
+ re = Regexp.compile('def')
+ result1 = 'abcdefg'.sub(re, '!!')
+ re = Regexp.compile('b')
+ result2 = 'abcabc'.sub(re, '<<\&>>')
+ re = Regexp.compile('x+(b+)')
+ result3 = 'xbbxbb'.sub(re, 'X<<\1>>')
+
+ result1 == "abc!!g" and
+ result2 == "a<<b>>cabc" and
+ result3 == "X<<bb>>xbb"
+ end
+
+ # TODO ATM broken assert('String#sub!', '15.2.10.5.37') do
+ assert('String#sub! with Regexp', '15.2.10.5.37') do
+ result1 = "String-String"
+ re = Regexp.compile('in.')
+ result1.sub!(re, "!!")
+
+ result2 = "String-String"
+ re = Regexp.compile('in.')
+ result2.sub!(re, '<<\&>>')
- result1 == "abc!!g" and
- result2 == "a<<b>>cabc" and
- result3 == "X<<bb>>xbb"
+ result1 == "Str!!-String" and
+ result2 == "Str<<ing>>-String"
+ end
+end # END: Object.const_defined?(:Regexp)
+
+assert('String#sub', '15.2.10.5.36') do
+ 'abcabc'.sub('b', 'B') == 'aBcabc' && 'abcabc'.sub('b') { |w| w.capitalize } == 'aBcabc'
end
-# TODO ATM broken assert('String#sub!', '15.2.10.5.37') do
assert('String#sub!', '15.2.10.5.37') do
- result1 = "String-String"
- re = Regexp.compile('in.')
- result1.sub!(re, "!!")
+ a = 'abcabc'
+ a.sub!('b', 'B')
- result2 = "String-String"
- re = Regexp.compile('in.')
- result2.sub!(re, '<<\&>>')
+ b = 'abcabc'
+ b.sub!('b') { |w| w.capitalize }
- result1 == "Str!!-String" and
- result2 == "Str<<ing>>-String"
+ a == 'aBcabc' && b == 'aBcabc'
end
-end # END: Object.const_defined?(:Regexp)
assert('String#to_i', '15.2.10.5.38') do
a = ''.to_i

0 comments on commit 9471c3f

Please sign in to comment.