spec/cocoa/nsattributedstring_spec.rb in sugarcube-3.1.1 vs spec/cocoa/nsattributedstring_spec.rb in sugarcube-3.2.0
- old
+ new
@@ -52,9 +52,53 @@
"\n test \n".attrd.strip.should == 'test'.attrd
"test ".attrd.strip.should == 'test'.attrd
"test\n ".attrd.strip.should == 'test'.attrd
" \n test".attrd.strip.should == 'test'.attrd
end
+ end
+ describe "should allow joining an array of attributed strings" do
+ it "should turn an array of strings into an attributed string" do
+ joined = ['a', 'b', 'c'].join_attrd
+ joined.is_a?(NSAttributedString).should == true
+ joined.is_a?(NSString).should == false
+ joined.isEqualToAttributedString('abc'.attrd).should == true
+
+ joined2 = ['a', 'b', 'c'].join_attrd('-')
+ joined2.isEqualToAttributedString('a-b-c'.attrd).should == true
+ end
+
+ it "should join attributed strings" do
+ joined = ['a'.attrd, 'b'.attrd, 'c'.attrd].join_attrd
+ joined.is_a?(NSAttributedString).should == true
+ end
+
+ it "should create an attributed string even when only one item is attributed" do
+ joined = ['a', 'b', 'c'.attrd].join_attrd
+ joined.is_a?(NSAttributedString).should == true
+
+ joined2 = ['a', 'b'.attrd, 'c'].join_attrd
+ joined2.is_a?(NSAttributedString).should == true
+ end
+
+ it "should preserve attributes when joining" do
+ joined = ['a'.italic, 'b'.bold, 'c'.underline].join_attrd
+ joined.isEqualToAttributedString('a'.italic + 'b'.bold + 'c'.underline).should == true
+ end
+
+ it "should join with a string" do
+ joined = ['a'.bold, 'b', 'c'].join_attrd('-')
+ joined.isEqualToAttributedString('a'.bold + '-' + 'b' + '-' + 'c').should == true
+ end
+
+ it "should join with an attributed string" do
+ joined = ['a'.bold, 'b', 'c'].join_attrd('-'.bold)
+ joined.isEqualToAttributedString('a'.bold + '-'.bold + 'b' + '-'.bold + 'c').should == true
+ end
+
+ it "should join an array of strings with an attributed connector" do
+ joined = ['a', 'b', 'c'].join_attrd('-'.bold)
+ joined.isEqualToAttributedString('a'.attrd + '-'.bold + 'b' + '-'.bold + 'c').should == true
+ end
end
end