Skip to content

Commit

Permalink
YAML should allow spaces. eg the trailing \s\t in YAML.load("!timesta…
Browse files Browse the repository at this point in the history
…mp '2009-03-22 00:00:00\s\t'") is allowed

Changed igem.bat, irake.bat, etc to work in dev environment where ir.exe is not in the path
File.expand_path("~") should throw ArgumentError is HOME is not set
  • Loading branch information
Shri Borde committed Mar 26, 2009
1 parent a90a894 commit 119b056
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 29 deletions.
Expand Up @@ -414,7 +414,52 @@ public class BaseConstructor : IEnumerable<object> {
throw new ConstructorException("could not determine a constructor for the tag: " + node.Tag);
}

private static Regex TIMESTAMP_REGEXP = new Regex("^(-?[0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:(?:[Tt]|[ \t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \t]*(Z|([-+][0-9][0-9]?)(?::([0-9][0-9])?)?)))?$");
private static Regex TIMESTAMP_REGEXP = new Regex(@"
^[ \t]*
( # Year
-?
[0-9][0-9][0-9][0-9]
)
-
([0-9][0-9]?) # Month
-
([0-9][0-9]?) # Day
(?:
(?:
[Tt]
|
[ \t]+
)
([0-9][0-9]?) # Hour
:
([0-9][0-9]) # Minute
:
([0-9][0-9]) # Seconds
(?:
\\.
([0-9]*) # Fractional seconds
)?
(?:
[ \t]*
( # utc
Z
|
([-+][0-9][0-9]?) # timezoneh
(?: # timezonem
:([0-9][0-9])?
)?
)?
)
)?
[ \t]*$",
RegexOptions.IgnorePatternWhitespace);

internal static Regex YMD_REGEXP = new Regex("^(-?[0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)$");

public static object ConstructYamlTimestampYMD(BaseConstructor ctor, Node node) {
Expand Down
Expand Up @@ -294,7 +294,7 @@ private class SimpleKey {

private void ScanToNextToken() {
while (true) {
while (Peek() == ' ') {
while (Peek() == ' ' || Peek() == '\t') {
Forward();
}
if (Peek() == '#') {
Expand Down
Expand Up @@ -39,15 +39,33 @@
File.expand_path(".", "#{@rootdir}").should == "#{@rootdir}"
end

# FIXME: do not use conditionals like this around #it blocks
unless not home = ENV['HOME'].tr('\\', '/')
it "converts a pathname to an absolute pathname, using ~ (home) as base" do
it "converts a pathname to an absolute pathname, using ~ (home) as base" do
home = ENV['HOME']
initial_home = home
begin
platform_is :windows do
if not home then
home = "c:\\Users\\janedoe"
ENV['HOME'] = home
end
home = home.tr '\\', '/'
end
File.expand_path('~').should == home
File.expand_path('~', '/tmp/gumby/ddd').should == home
File.expand_path('~/a', '/tmp/gumby/ddd').should == File.join(home, 'a')
File.expand_path('~a').should == '~a'
File.expand_path('~/').should == home
File.expand_path('~/..badfilename').should == "#{home}/..badfilename"
File.expand_path('~/a','~/b').should == "#{home}/a"


ENV['HOME'] = nil
lambda { File.expand_path('~') }.should raise_error(ArgumentError)
ensure
ENV['HOME'] = initial_home
end
end

platform_is_not :windows do
# FIXME: these are insane!
it "expand path with " do
Expand All @@ -64,11 +82,8 @@
File.expand_path('./////').should == Dir.pwd
File.expand_path('.').should == Dir.pwd
File.expand_path(Dir.pwd).should == Dir.pwd
File.expand_path('~/').should == ENV['HOME']
File.expand_path('~/..badfilename').should == "#{ENV['HOME']}/..badfilename"
File.expand_path('..').should == Dir.pwd.split('/')[0...-1].join("/")
File.expand_path('//').should == '//'
File.expand_path('~/a','~/b').should == "#{ENV['HOME']}/a"
end

it "raises an ArgumentError if the path is not valid" do
Expand Down
Expand Up @@ -138,6 +138,10 @@ class UserString < String
include AnAttribute
end

class UserRange < Range
include AnAttribute
end

module Meths
def meths_method() end
end
Expand All @@ -161,6 +165,9 @@ module MarshalSpec
"'a'..'b'" => [('a'..'b'),
"\004\bo:\nRange\b:\nbegin\"\006a:\texclF:\bend\"\006b",
{ :begin => 'a', :end => 'b', :exclude_end? => false }],
"Range subclass" => [UserRange.new(1,2),
"\004\bo:\016UserRange\t:\bendi\a:\nbegini\006:\texclF:\a@ai\006",
{ :begin => 1, :end => 2, :exclude_end? => false, :a => 1 }],
"Struct" => [Struct::Useful.new(1, 2),
"\004\bS:\023Struct::Useful\a:\006ai\006:\006bi\a"],
"Symbol" => [:symbol,
Expand Down
Expand Up @@ -16,7 +16,7 @@

it "loads strings" do
strings = ["str",
" str",
"\s\tstr\s\t",
"'str'",
"str",
" str",
Expand Down Expand Up @@ -87,4 +87,8 @@
expected = { :"user name" => "This is the user name."}
YAML.load(string).should == expected
end

it "ignores whitespace" do
YAML.load("!timestamp \s\t '\s\t 2009-03-22 \s\t 00:00:00 \s\t'").class.should == Time
end
end
Expand Up @@ -504,20 +504,36 @@ public static class Constants {
private static MutableString/*!*/ ExpandPath(RubyContext/*!*/ context, MutableString/*!*/ path) {
PlatformAdaptationLayer pal = context.DomainManager.Platform;
int length = path.Length;
bool raisingRubyException = false;
try {
if (path == null || length == 0)
return Glob.CanonicalizePath(MutableString.Create(Directory.GetCurrentDirectory()));

if (length == 1 && path.GetChar(0) == '~')
return Glob.CanonicalizePath(MutableString.Create(Path.GetFullPath(pal.GetEnvironmentVariable("HOME"))));
if (path.GetChar(0) == '~') {
if (length == 1 || (path.GetChar(1) == Path.DirectorySeparatorChar ||
path.GetChar(1) == Path.AltDirectorySeparatorChar)) {

if (path.GetChar(0) == '~' && (path.GetChar(1) == Path.DirectorySeparatorChar || path.GetChar(1) == Path.AltDirectorySeparatorChar)) {
string homeDirectory = pal.GetEnvironmentVariable("HOME");
return Glob.CanonicalizePath(length < 3 ? MutableString.Create(homeDirectory) : MutableString.Create(Path.Combine(homeDirectory, path.GetSlice(2).ConvertToString())));
string homeDirectory = pal.GetEnvironmentVariable("HOME");
if (homeDirectory == null) {
raisingRubyException = true;
throw RubyExceptions.CreateArgumentError("couldn't find HOME environment -- expanding `~'");
}
if (length <= 2) {
path = MutableString.Create(homeDirectory);
} else {
path = MutableString.Create(Path.Combine(homeDirectory, path.GetSlice(2).ConvertToString()));
}
return Glob.CanonicalizePath(path);
} else {
return path;
}
} else {
return Glob.CanonicalizePath(MutableString.Create(Path.GetFullPath(path.ConvertToString())));
}
} catch (Exception e) {
if (raisingRubyException) {
throw;
}
// Re-throw exception as a reasonable Ruby exception
throw new Errno.InvalidError(path.ConvertToString(), e);
}
Expand Down
Expand Up @@ -279,9 +279,10 @@ class SubclassData {
}

private void WriteRange(Range/*!*/ range) {
_writer.Write((byte)'o');
WriteSymbol("Range");
WriteObject(range);
WriteInt32(3);
// Write the attributes that are implemented in C#. Any user-defined attributes (for subtypes of Range)
// will be handled by the default handling of IRubyObject
WriteSymbol("begin");
WriteAnObject(range.Begin);
WriteSymbol("end");
Expand Down
12 changes: 10 additions & 2 deletions Merlin/Main/Languages/Ruby/Scripts/bin/igem.bat
@@ -1,2 +1,10 @@
@ECHO OFF
@"ir.exe" "%~dpn0" %*
@echo off
setlocal

set IR_CMD="%~dp0ir.exe"
if defined MERLIN_ROOT (
REM - This is a dev environment. See http://wiki.github.com/ironruby/ironruby
set IR_CMD="%MERLIN_ROOT%\bin\Debug\ir.exe"
)

%IR_CMD% "%~dpn0" %*
12 changes: 10 additions & 2 deletions Merlin/Main/Languages/Ruby/Scripts/bin/iirb.bat
@@ -1,2 +1,10 @@
@ECHO OFF
"%~d0%~p0ir.exe" "%~d0%~p0%~n0" %*
@echo off
setlocal

set IR_CMD="%~dp0ir.exe"
if defined MERLIN_ROOT (
REM - This is a dev environment. See http://wiki.github.com/ironruby/ironruby
set IR_CMD="%MERLIN_ROOT%\bin\Debug\ir.exe"
)

%IR_CMD% "%~dpn0" %*
12 changes: 10 additions & 2 deletions Merlin/Main/Languages/Ruby/Scripts/bin/irails.bat
@@ -1,2 +1,10 @@
@ECHO OFF
@"ir.exe" "%~dpn0" %*
@echo off
setlocal

set IR_CMD="%~dp0ir.exe"
if defined MERLIN_ROOT (
REM - This is a dev environment. See http://wiki.github.com/ironruby/ironruby
set IR_CMD="%MERLIN_ROOT%\bin\Debug\ir.exe"
)

%IR_CMD% "%~dpn0" %*
12 changes: 10 additions & 2 deletions Merlin/Main/Languages/Ruby/Scripts/bin/irake.bat
@@ -1,2 +1,10 @@
@ECHO OFF
@"ir.exe" "%~dpn0" %*
@echo off
setlocal

set IR_CMD="%~dp0ir.exe"
if defined MERLIN_ROOT (
REM - This is a dev environment. See http://wiki.github.com/ironruby/ironruby
set IR_CMD="%MERLIN_ROOT%\bin\Debug\ir.exe"
)

%IR_CMD% "%~dpn0" %*
12 changes: 10 additions & 2 deletions Merlin/Main/Languages/Ruby/Scripts/bin/irdoc.bat
@@ -1,2 +1,10 @@
@ECHO OFF
"%~d0%~p0ir.exe" "%~d0%~p0%~n0" %*
@echo off
setlocal

set IR_CMD="%~dp0ir.exe"
if defined MERLIN_ROOT (
REM - This is a dev environment. See http://wiki.github.com/ironruby/ironruby
set IR_CMD="%MERLIN_ROOT%\bin\Debug\ir.exe"
)

%IR_CMD% "%~dpn0" %*
12 changes: 10 additions & 2 deletions Merlin/Main/Languages/Ruby/Scripts/bin/iri.bat
@@ -1,2 +1,10 @@
@ECHO OFF
"%~d0%~p0ir.exe" "%~d0%~p0%~n0" %*
@echo off
setlocal

set IR_CMD="%~dp0ir.exe"
if defined MERLIN_ROOT (
REM - This is a dev environment. See http://wiki.github.com/ironruby/ironruby
set IR_CMD="%MERLIN_ROOT%\bin\Debug\ir.exe"
)

%IR_CMD% "%~dpn0" %*

0 comments on commit 119b056

Please sign in to comment.