Class: TestKyaniteStringCast

Inherits
UnitTest
  • Object
show all
Defined in
test/string/test_cast.rb

Tests for String

String Additions

Kyanite definitions

String

Kyanite tests and examples

Cast Chars Diff Database-Helper Miscellaneous Nested Split

Usage

require 'kyanite/string'

Required from Facets String:

shatter(re)

Breaks a string up into an array based on a regular expression. Similar to scan, but includes the matches.

Instance Method Summary (collapse)

Instance Method Details

- (Object) test_to_identifier



69
70
71
72
73
74
75
76
77
78
79
80
# File 'test/string/test_cast.rb', line 69

def test_to_identifier
  assert_equal 1,           '1'.to_identifier
  assert_equal 2,           '   2'.to_identifier
  assert_equal 3,           '   3    '.to_identifier
  assert_equal 4,           '4    '.to_identifier
  assert_equal 'a',         'a    '.to_identifier
  assert_equal 'b',         ' b    '.to_identifier
  assert_equal 'c',         '    c'.to_identifier
  assert_equal 'hallo123',  '    hallo123 '.to_identifier
  assert_equal 123,         '    123hallo '.to_identifier
  assert_equal 123,         '    123hallo456  '.to_identifier
end

- (Object) test_to_integer



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'test/string/test_cast.rb', line 26

def test_to_integer
	assert_equal nil, "Hallo".to_integer
	assert_equal 0, "Hallo0".to_integer
	assert_equal 0, "0Hallo".to_integer
	assert_equal nil, "".to_integer
	assert_equal nil, nil.to_integer
	assert_equal 23, 23.to_integer

	# macht alles noch die alte Funktion to_i
	assert_equal 123, "123Hallo2".to_integer
	assert_equal 123, "123 Hallo2".to_integer
	assert_equal 123, " 123 Hällo2".to_integer
	assert_equal -123, " -123 Hallo2".to_integer
	assert_equal -1, " -1,23 Hallo2".to_integer

	# jetzt kommt die neue Funktionalität zum Zuge
	assert_equal 42, "Hallo42".to_integer
	assert_equal 42, "Hallo42JoJo".to_integer
	assert_equal 42, " Hällo-42".to_integer
	assert_equal 42, "Hallo42.1".to_integer	
	assert_equal 42, "Hallo42,1".to_integer	
end

- (Object) test_to_integer_optional



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'test/string/test_cast.rb', line 51

def test_to_integer_optional	
	assert_equal "Hallo", "Hallo".to_integer_optional
	assert_equal "Hallo0", "Hallo0".to_integer_optional
	assert_equal 0, "0Hallo".to_integer_optional
	assert_equal nil, "".to_integer_optional
	assert_equal nil, nil.to_integer_optional
	assert_equal 23, 23.to_integer_optional

	assert_equal 123, "123Hallo2".to_integer_optional
	assert_equal 123, "123 Hallo2".to_integer_optional
	assert_equal " 123 Hällo2", " 123 Hällo2".to_integer_optional   # Spaces am Anfang sind nicht erlaubt
	assert_equal -123, "-123 Hallo2".to_integer_optional
	assert_equal -1, "-1,23 Hallo2".to_integer_optional
	assert_equal "Hallo42", "Hallo42".to_integer_optional
end

- (Object) test_to_nil



19
20
21
22
23
# File 'test/string/test_cast.rb', line 19

def test_to_nil
	assert_equal 'e', 'e'.to_nil
	assert_equal nil, ''.to_nil    
	assert_equal nil, nil.to_nil
end