Skip to content

Commit

Permalink
more tests converted
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 30, 2015
1 parent 26734c6 commit 1146a01
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 118 deletions.
92 changes: 92 additions & 0 deletions library/types/test/string_test.rb
Expand Up @@ -5,6 +5,11 @@
Yast.import "String"

describe Yast::String do
before do
# ensure proper default locale
ENV["LANG"] = "C"
end

describe ".Quote" do
it "returns empty string if nil passed" do
expect(subject.Quote(nil)).to eq ""
Expand All @@ -17,4 +22,91 @@
expect(subject.Quote("a'b'c")).to eq "a'\\''b'\\''c"
end
end

describe ".UnQuote" do
it "returns empty string if nil passed" do
expect(subject.UnQuote(nil)).to eq ""
end

it "returns unescaped single quotes" do
expect(subject.UnQuote("")).to eq ""
expect(subject.UnQuote("a")).to eq "a"
expect(subject.UnQuote("a'\\''b")).to eq "a'b"
expect(subject.UnQuote("a'\\''b'\\''c")).to eq "a'b'c"
end
end

describe ".FormatSize" do
it "returns empty string if nil passed" do
expect(subject.FormatSize(nil)).to eq ""
end

FORMAT_SIZE_DATA = {
0 => "0 B",
1 => "1 B",
1025 => "1 KiB",
1125 => "1.1 KiB",
743 * 1024 => "743 KiB",
1_049_000 => "1.00 MiB",
1_074_000_000 => "1.000 GiB",
1_100_000_000_000 => "1.000 TiB",
1_126_000_000_000_000 => "1024.091 TiB",
1 << 10 => "1 KiB",
1 << 20 => "1.00 MiB",
1 << 30 => "1.000 GiB",
1 << 40 => "1.000 TiB"
}

it "returns size formatted with proper bytes units" do
FORMAT_SIZE_DATA.each do |arg, res|
expect(subject.FormatSize(arg)).to eq res
end
end
end

describe ".FormatSizeWithPrecision" do
it "returns empty string if nil passed" do
expect(subject.FormatSizeWithPrecision(nil, nil, nil)).to eq ""
end

it "returns bytes in proper unit with passed precision forcing trailing zeroes if omit_zeroes not passed" do
expect(subject.FormatSizeWithPrecision(1025 << 30, 2, false)).to eq "1.00 TiB"
expect(subject.FormatSizeWithPrecision(1025 << 30, 3, false)).to eq "1.001 TiB"
end

it "returns bytes with precision based on suffix if negative precision passed" do
expect(subject.FormatSizeWithPrecision(1025 << 30, -1, false)).to eq "1.001 TiB"
expect(subject.FormatSizeWithPrecision(1025, -1, false)).to eq "1.0 KiB"
end

it "omit trailing zeros if omit_zeroes is passed as true" do
expect(subject.FormatSizeWithPrecision(4097, 2, true)).to eq "4 KiB"
expect(subject.FormatSizeWithPrecision(1 << 20, 2, true)).to eq "1 MiB"
expect(subject.FormatSizeWithPrecision(1025, 2, true)).to eq "1 KiB"
expect(subject.FormatSizeWithPrecision(8 << 30, 2, true)).to eq "8 GiB"
end
end

describe ".CutBlanks" do
it "return empty string for nil" do
expect(subject.CutBlanks(nil)).to eq ""
end

CUT_BLANKS_DATA = {
"abc" => "abc",
" abc" => "abc",
"abc " => "abc",
" abc " => "abc",
"\tabc " => "abc",
"\tabc\t " => "abc",
" \tabc\t " => "abc",
"\t a b c \t" => "a b c",
"\t a b c \t\n" => "a b c \t\n"
}
it "remove trailing and prepending whitespace" do
CUT_BLANKS_DATA.each do |arg, res|
expect(subject.CutBlanks(arg)).to eq res
end
end
end
end
56 changes: 0 additions & 56 deletions library/types/testsuite/tests/String.out
@@ -1,59 +1,3 @@
Dump String::UnQuote
Return
Return
Return a
Return a'b
Return a'b'c
Dump String::FormatSize
Return
Return 0 B
Return 1 B
Return 1 KiB
Return 1.1 KiB
Return 743 KiB
Return 1.00 MiB
Return 1.000 GiB
Return 1.000 TiB
Return 1024.091 TiB
Return 1 KiB
Return 1.00 MiB
Return 1.000 GiB
Return 1.000 TiB
Dump String::FormatSizeWithPrecision
Return
Return 0 B
Return 1.00 B
Return 1.001 KiB
Return 1 MiB
Return 1 MiB
Return 1 GiB
Return 1.000 GiB
Return 1.00 TiB
Return 1024.1 TiB
Return 4 KiB
Return 4.00 KiB
Return 4 KiB
Return 8 GiB
Return 15.00000 B
Return 21.846 GiB
Dump String::CutBlanks
Return
Return
Return
Return abc
Return abc
Return abc
Return abc
Return abc
Return abc
Return ab c
Return ab c
Return ab c
Return ab c
Return ab c
Return ab c
Return ab c
Return ab c
Dump String::CutZeros
Return
Return
Expand Down
62 changes: 0 additions & 62 deletions library/types/testsuite/tests/String.rb
Expand Up @@ -27,68 +27,6 @@ def main
Yast.include self, "testsuite.rb"
Yast.import "String"

DUMP("String::UnQuote")
TEST(->() { String.UnQuote(nil) }, [], nil)
TEST(->() { String.UnQuote("") }, [], nil)
TEST(->() { String.UnQuote("a") }, [], nil)
TEST(->() { String.UnQuote("a'\\''b") }, [], nil)
TEST(->() { String.UnQuote("a'\\''b'\\''c") }, [], nil)

DUMP("String::FormatSize")
TEST(->() { String.FormatSize(nil) }, [], nil)
TEST(->() { String.FormatSize(0) }, [], nil)
TEST(->() { String.FormatSize(1) }, [], nil)
TEST(->() { String.FormatSize(1025) }, [], nil)
TEST(->() { String.FormatSize(1125) }, [], nil)
TEST(->() { String.FormatSize(743 * 1024) }, [], nil)
TEST(->() { String.FormatSize(1_049_000) }, [], nil)
TEST(->() { String.FormatSize(1_074_000_000) }, [], nil)
TEST(->() { String.FormatSize(1_100_000_000_000) }, [], nil)
TEST(->() { String.FormatSize(1_126_000_000_000_000) }, [], nil)
TEST(->() { String.FormatSize(1 << 10) }, [], nil)
TEST(->() { String.FormatSize(1 << 20) }, [], nil)
TEST(->() { String.FormatSize(1 << 30) }, [], nil)
TEST(->() { String.FormatSize(1 << 40) }, [], nil)

DUMP("String::FormatSizeWithPrecision")
TEST(->() { String.FormatSizeWithPrecision(nil, nil, nil) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(0, nil, true) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(1, 2, false) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(1025, 3, false) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(1024 * 1024, 2, true) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(1_049_000, 2, true) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(1024 * 1024 * 1024, 2, true) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(1_074_000_000, 3, false) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(1_100_000_000_000, 2, false) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(1_126_000_000_000_000, 1, true) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(4096, 2, true) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(4096, 2, false) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(4097, 2, true) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(8_589_934_592, 2, true) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(15, 5, false) }, [], nil)
TEST(->() { String.FormatSizeWithPrecision(23_456_767_890, 3, true) }, [], nil)

DUMP("String::CutBlanks")
TEST(->() { String.CutBlanks(nil) }, [], nil)
TEST(->() { String.CutBlanks("") }, [], nil)
TEST(->() { String.CutBlanks(" ") }, [], nil)

TEST(->() { String.CutBlanks("abc") }, [], nil)
TEST(->() { String.CutBlanks(" abc") }, [], nil)
TEST(->() { String.CutBlanks("abc ") }, [], nil)
TEST(->() { String.CutBlanks(" abc ") }, [], nil)
TEST(->() { String.CutBlanks(" abc") }, [], nil)
TEST(->() { String.CutBlanks("abc ") }, [], nil)

TEST(->() { String.CutBlanks("ab c") }, [], nil)
TEST(->() { String.CutBlanks(" ab c") }, [], nil)
TEST(->() { String.CutBlanks("ab c ") }, [], nil)
TEST(->() { String.CutBlanks(" ab c ") }, [], nil)
TEST(->() { String.CutBlanks(" ab c") }, [], nil)
TEST(->() { String.CutBlanks("ab c ") }, [], nil)
TEST(->() { String.CutBlanks(" ab c ") }, [], nil)
TEST(->() { String.CutBlanks("ab c") }, [], nil)

DUMP("String::CutZeros")
TEST(->() { String.CutZeros(nil) }, [], nil)
TEST(->() { String.CutZeros("") }, [], nil)
Expand Down

0 comments on commit 1146a01

Please sign in to comment.