Skip to content
Permalink
Browse files
[Truffle] Last of the top-level language Regexp specs.
  • Loading branch information
chrisseaton committed Dec 6, 2014
1 parent 6127af9 commit 3cbe259328974c17915fa54b71e95c9f2ef4050b
@@ -36,7 +36,7 @@ public StringToRegexpNode(StringToRegexpNode prev) {
public RubyRegexp doString(RubyString string) {
notDesignedForCompilation();

return new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), string.toString(), Option.DEFAULT);
return new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), string.getBytes(), Option.DEFAULT);
}

}
@@ -149,7 +149,7 @@ public InitializeNode(InitializeNode prev) {
public RubyRegexp initialize(RubyRegexp regexp, RubyString string) {
notDesignedForCompilation();

regexp.initialize(this, string.toString());
regexp.initialize(this, string.getBytes());
return regexp;
}

@@ -219,8 +219,26 @@ public SourceNode(SourceNode prev) {
}

@Specialization
public Object source(RubyRegexp regexp) {
return getContext().makeString(regexp.getSource());
public RubyString source(RubyRegexp regexp) {
return getContext().makeString(regexp.getSource().toString());
}

}

@CoreMethod(names = "to_s")
public abstract static class ToSNode extends CoreMethodNode {

public ToSNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public ToSNode(ToSNode prev) {
super(prev);
}

@Specialization
public RubyString to_s(RubyRegexp regexp) {
return getContext().makeString(org.jruby.RubyRegexp.newRegexp(getContext().getRuntime(), regexp.getSource()).to_s().toString());
}

}
@@ -499,7 +499,7 @@ public GsubNode(GsubNode prev) {
public RubyString gsub(VirtualFrame frame, RubyString string, RubyString regexpString, RubyString replacement) {
notDesignedForCompilation();

final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), escape(frame, regexpString).toString(), Option.DEFAULT);
final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), escape(frame, regexpString).getBytes(), Option.DEFAULT);
return gsub(string, regexp, replacement);
}

@@ -640,7 +640,7 @@ public MatchNode(MatchNode prev) {
public Object match(RubyString string, RubyString regexpString) {
notDesignedForCompilation();

final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), regexpString.toString(), Option.DEFAULT);
final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), regexpString.getBytes(), Option.DEFAULT);
return regexp.matchCommon(string.getBytes(), false);
}

@@ -718,7 +718,7 @@ public ScanNode(ScanNode prev) {
public RubyArray scan(RubyString string, RubyString regexpString) {
notDesignedForCompilation();

final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), regexpString.toString(), Option.DEFAULT);
final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), regexpString.getBytes(), Option.DEFAULT);
return scan(string, regexp);
}

@@ -835,7 +835,7 @@ public SubNode(SubNode prev) {
public RubyString sub(VirtualFrame frame, RubyString string, RubyString regexpString, RubyString replacement) {
notDesignedForCompilation();

final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), escape(frame, regexpString).toString(), Option.DEFAULT);
final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), escape(frame, regexpString).getBytes(), Option.DEFAULT);
return sub(string, regexp, replacement);
}

@@ -52,28 +52,28 @@ public RubyBasicObject newInstance(RubyNode currentNode) {
}

@CompilationFinal private Regex regex;
@CompilationFinal private String source;
@CompilationFinal private ByteList source;

public RubyRegexp(RubyClass regexpClass) {
super(regexpClass);
}

public RubyRegexp(RubyNode currentNode, RubyClass regexpClass, String regex, int options) {
public RubyRegexp(RubyNode currentNode, RubyClass regexpClass, ByteList regex, int options) {
this(regexpClass);
initialize(compile(currentNode, getContext(), regex, options), regex);
}

public RubyRegexp(RubyClass regexpClass, Regex regex, String source) {
public RubyRegexp(RubyClass regexpClass, Regex regex, ByteList source) {
this(regexpClass);
initialize(regex, source);
}

public void initialize(RubyNode currentNode, String setSource) {
public void initialize(RubyNode currentNode, ByteList setSource) {
regex = compile(currentNode, getContext(), setSource, Option.DEFAULT);
source = setSource;
}

public void initialize(Regex setRegex, String setSource) {
public void initialize(Regex setRegex, ByteList setSource) {
regex = setRegex;
source = setSource;
}
@@ -82,7 +82,7 @@ public Regex getRegex() {
return regex;
}

public String getSource() {
public ByteList getSource() {
return source;
}

@@ -315,11 +315,9 @@ public boolean equals(Object obj) {
return true;
}

public static Regex compile(RubyNode currentNode, RubyContext context, String pattern, int options) {
public static Regex compile(RubyNode currentNode, RubyContext context, ByteList bytes, int options) {
RubyNode.notDesignedForCompilation();

final byte[] bytes = pattern.getBytes(StandardCharsets.UTF_8);
return compile(currentNode, context, bytes, UTF8Encoding.INSTANCE, options);
return compile(currentNode, context, bytes.bytes(), UTF8Encoding.INSTANCE, options);
}

public static Regex compile(RubyNode currentNode, RubyContext context, byte[] bytes, Encoding encoding, int options) {
@@ -1884,7 +1884,7 @@ public RubyNode visitRedoNode(org.jruby.ast.RedoNode node) {
public RubyNode visitRegexpNode(org.jruby.ast.RegexpNode node) {
Regex regex = RubyRegexp.compile(currentNode, context, node.getValue().bytes(), node.getEncoding(), node.getOptions().toOptions());

final RubyRegexp regexp = new RubyRegexp(context.getCoreLibrary().getRegexpClass(), regex, node.getValue().toString());
final RubyRegexp regexp = new RubyRegexp(context.getCoreLibrary().getRegexpClass(), regex, node.getValue());
final ObjectLiteralNode literalNode = new ObjectLiteralNode(context, translate(node.getPosition()), regexp);
return literalNode;
}
@@ -42,3 +42,29 @@ fails:Regexp.new given a Regexp sets the encoding to EUC-JP if the Regexp litera
fails:Regexp.new given a Regexp sets the encoding to Windows-31J if the Regexp literal has the 's' option
fails:Regexp.new given a Regexp sets the encoding to US-ASCII if the Regexp literal has the 'n' option and the source String is ASCII only
fails:Regexp.new given a Regexp sets the encoding to source String's encoding if the Regexp literal has the 'n' option and the source String is not ASCII only
fails:Regexp.new given a String with escaped characters accepts a three-digit octal value
fails:Regexp.new given a String with escaped characters interprets a digit following a three-digit octal value as a character
fails:Regexp.new given a String with escaped characters accepts '\M-\n'
fails:Regexp.new given a String with escaped characters accepts '\M-\t'
fails:Regexp.new given a String with escaped characters accepts '\M-\r'
fails:Regexp.new given a String with escaped characters accepts '\M-\f'
fails:Regexp.new given a String with escaped characters accepts '\M-\v'
fails:Regexp.new given a String with escaped characters accepts '\M-\a'
fails:Regexp.new given a String with escaped characters accepts '\M-\e'
fails:Regexp.new given a String with escaped characters accepts '\M-\C-\n'
fails:Regexp.new given a String with escaped characters accepts '\M-\C-\t'
fails:Regexp.new given a String with escaped characters accepts '\M-\C-\r'
fails:Regexp.new given a String with escaped characters accepts '\M-\C-\f'
fails:Regexp.new given a String with escaped characters accepts '\M-\C-\v'
fails:Regexp.new given a String with escaped characters accepts '\M-\C-\a'
fails:Regexp.new given a String with escaped characters accepts '\M-\C-\e'
fails:Regexp.new given a String with escaped characters accepts '\M-\c\n'
fails:Regexp.new given a String with escaped characters accepts '\M-\c\t'
fails:Regexp.new given a String with escaped characters accepts '\M-\c\r'
fails:Regexp.new given a String with escaped characters accepts '\M-\c\f'
fails:Regexp.new given a String with escaped characters accepts '\M-\c\v'
fails:Regexp.new given a String with escaped characters accepts '\M-\c\a'
fails:Regexp.new given a String with escaped characters accepts '\M-\c\e'
fails:Regexp.new given a String with escaped characters accepts '\M-\c\n'
fails:Regexp.new given a String with escaped characters accepts '\M-\C-\n'
fails:Regexp.new given a String with escaped characters accepts '\M-\n'

This file was deleted.

@@ -93,6 +93,7 @@ class MSpecScript
"^spec/ruby/core/regexp/source_spec.rb",
"^spec/ruby/core/regexp/fixed_encoding_spec.rb",
"^spec/ruby/core/regexp/encoding_spec.rb",
"^spec/ruby/core/regexp/new_spec.rb",
"^spec/ruby/core/signal/list_spec.rb",
"^spec/ruby/core/string/chomp_spec.rb",
"^spec/ruby/core/string/crypt_spec.rb",

0 comments on commit 3cbe259

Please sign in to comment.