1 require File.dirname(__FILE__) + '/../../spec_helper'
2 require 'rat/core_ext/string'
5 describe "#constantize" do
6 it "should constantize a simple word" do
7 "test".constantize.should == "Test"
10 it "should constantize a snake_case word" do
11 "snake_case".constantize.should == "SnakeCase"
14 it "should constantize a simple string" do
15 "a simple string".constantize.should == "ASimpleString"
20 it "should concatenate another string onto this string with File::SEPARATOR" do
21 ("abc" / "def").should == "abc#{File::SEPARATOR}def"
26 it "should be UTF-8 safe" do
27 "▲▼▶◀".length.should == 4
28 "▁▂▃▄▅▆▇█".length.should == 8
31 it "should be UTF-16 safe" do
32 pending("unsure how to manage this - most editors won't even print these right")
37 describe "#fixed_split" do
38 it "should work correctly when the last character is the same as the seperator" do
39 '.a.b.c.'.fixed_split('.').should == ['','a','b','c','']
43 describe "#split_at" do
44 it "should split a string into groups at a given length" do
45 'abcdefghijkl'.split_at(3).should == ['abc','def','ghi','jkl']
50 it "should indent a single-line string" do
52 indented = string.indent(' ')
53 indented.should == ' abcdef'
56 it "should indent a multi-line string using another string" do
57 string = "abcdef\nghijkl"
58 indented = string.indent('- ')
59 indented.should == "- abcdef\n- ghijkl"
62 it "should indent a multi-line string using a width" do
63 string = "abcdef\nghijkl"
64 indented = string.indent(2)
65 indented.should == " abcdef\n ghijkl"
68 it "should preserve inline whitespace" do
69 string = "begin\n puts 'whee!'\nend"
70 indented = string.indent(' ')
71 indented.should == " begin\n puts 'whee!'\n end"
74 it "should preserve prefixed whitespace" do
76 indented = string.indent(' ')
77 indented.should == " \n I am low"
80 it "should preserve postfixed whitespace" do
81 string = "I am high\n"
82 indented = string.indent(' ')
83 indented.should == " I am high\n "
86 it "should raise if incorrectly duck punched" do
87 lambda { "a string".indent(2..4) }.should raise_error ArgumentError,
88 "2..4 is neither string-ish nor numeric-ish"
93 it "should split a string as close to the boundary as possible" do
94 string = "This is a string"
95 wrapped = string.wrap(10)
96 wrapped.should == "This is a \nstring"
99 it "should split a word if no natural split is available" do
100 string = "Pneumonoultramicroscopicsilicovolcanokoniosis"
101 wrapped = string.wrap(15)
102 wrapped.should == "Pneumonoultrami\ncroscopicsilico\nvolcanokoniosis"
105 it "should prefer to split a word if the nearest natural split is too far from the boundary" do
106 string = "This was pneumonoultramicroscopicsilicovolcanokoniosis"
107 wrapped = string.wrap(15)
108 wrapped.should == "This was pneumo\nnoultramicrosco\npicsilicovolcan\nokoniosis"
111 it "should correctly handle line returns" do
112 string = "\n \n This is a string\n "
113 wrapped = string.wrap(10)
114 wrapped.should == "\n \n This is \na string\n "