rice 4.3.0 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,88 +1,88 @@
1
- #include "unittest.hpp"
2
- #include "embed_ruby.hpp"
3
- #include <rice/rice.hpp>
4
- #include <ruby/encoding.h>
5
- #include <rice/stl.hpp>
6
-
7
- #include <optional>
8
-
9
- using namespace Rice;
10
-
11
- TESTSUITE(StlStringView);
12
-
13
- SETUP(StlStringView)
14
- {
15
- embed_ruby();
16
- }
17
-
18
- TESTCASE(std_string_view_to_ruby)
19
- {
20
- ASSERT(rb_equal(String("").value(), detail::to_ruby(std::string_view(""))));
21
- ASSERT(rb_equal(String("foo").value(), detail::to_ruby(std::string_view("foo"))));
22
- }
23
-
24
- TESTCASE(std_string_view_to_ruby_encoding)
25
- {
26
- VALUE value = detail::to_ruby(std::string_view("Some String"));
27
- String string(value);
28
- Object encoding = string.call("encoding");
29
- String encodingName = encoding.call("name");
30
- std::string_view result = detail::From_Ruby<std::string_view>().convert(encodingName);
31
- if(result != "ASCII-8BIT" && result != "US-ASCII" && result != "UTF-8") {
32
- FAIL("Encoding incorrect", "ASCII-8BIT, US-ASCII, or UTF-8 (Windows)", result);
33
- }
34
- }
35
-
36
- TESTCASE(std_string_view_to_ruby_encoding_utf8)
37
- {
38
- rb_encoding* defaultEncoding = rb_default_external_encoding();
39
-
40
- VALUE utf8Encoding = rb_enc_from_encoding(rb_utf8_encoding());
41
- rb_enc_set_default_external(utf8Encoding);
42
-
43
- VALUE value = detail::to_ruby(std::string_view("Some String"));
44
- Object object(value);
45
- Object encoding = object.call("encoding");
46
- Object encodingName = encoding.call("name");
47
- ASSERT_EQUAL("UTF-8", detail::From_Ruby<std::string_view>().convert(encodingName));
48
-
49
- rb_enc_set_default_external(rb_enc_from_encoding(defaultEncoding));
50
- }
51
-
52
- TESTCASE(std_string_view_from_ruby)
53
- {
54
- ASSERT_EQUAL(std::string_view(""), detail::From_Ruby<std::string_view>().convert(rb_str_new2("")));
55
- ASSERT_EQUAL(std::string_view("foo"), detail::From_Ruby<std::string_view>().convert(rb_str_new2("foo")));
56
-
57
- ASSERT_EXCEPTION_CHECK(
58
- Exception,
59
- detail::From_Ruby<std::string_view>().convert(rb_float_new(15.512)),
60
- ASSERT_EQUAL("wrong argument type Float (expected String)", ex.what())
61
- );
62
- }
63
-
64
- TESTCASE(std_string_view_to_ruby_with_binary)
65
- {
66
- Rice::String got = detail::to_ruby(std::string_view("\000test", 5));
67
-
68
- ASSERT_EQUAL(String(std::string_view("\000test", 5)), got);
69
- ASSERT_EQUAL(5ul, got.length());
70
- }
71
-
72
- TESTCASE(std_string_view_from_ruby_with_binary)
73
- {
74
- std::string_view got = detail::From_Ruby<std::string_view>().convert(rb_str_new("\000test", 5));
75
- ASSERT_EQUAL(5ul, got.length());
76
- ASSERT_EQUAL(std::string_view("\000test", 5), got);
77
- }
78
-
79
- TESTCASE(std_string_view_from_ruby_refefence)
80
- {
81
- VALUE value = rb_str_new("test", 4);
82
- std::string_view view = detail::From_Ruby<std::string_view>().convert(value);
83
- ASSERT_EQUAL("test", view);
84
-
85
- String string(value);
86
- string.instance_eval("self[1] = 'a'");
87
- //ASSERT_EQUAL("tast", view);
88
- }
1
+ #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
3
+ #include <rice/rice.hpp>
4
+ #include <ruby/encoding.h>
5
+ #include <rice/stl.hpp>
6
+
7
+ #include <optional>
8
+
9
+ using namespace Rice;
10
+
11
+ TESTSUITE(StlStringView);
12
+
13
+ SETUP(StlStringView)
14
+ {
15
+ embed_ruby();
16
+ }
17
+
18
+ TESTCASE(std_string_view_to_ruby)
19
+ {
20
+ ASSERT(rb_equal(String("").value(), detail::to_ruby(std::string_view(""))));
21
+ ASSERT(rb_equal(String("foo").value(), detail::to_ruby(std::string_view("foo"))));
22
+ }
23
+
24
+ TESTCASE(std_string_view_to_ruby_encoding)
25
+ {
26
+ VALUE value = detail::to_ruby(std::string_view("Some String"));
27
+ String string(value);
28
+ Object encoding = string.call("encoding");
29
+ String encodingName = encoding.call("name");
30
+ std::string_view result = detail::From_Ruby<std::string_view>().convert(encodingName);
31
+ if(result != "ASCII-8BIT" && result != "US-ASCII" && result != "UTF-8") {
32
+ FAIL("Encoding incorrect", "ASCII-8BIT, US-ASCII, or UTF-8 (Windows)", result);
33
+ }
34
+ }
35
+
36
+ TESTCASE(std_string_view_to_ruby_encoding_utf8)
37
+ {
38
+ rb_encoding* defaultEncoding = rb_default_external_encoding();
39
+
40
+ VALUE utf8Encoding = rb_enc_from_encoding(rb_utf8_encoding());
41
+ rb_enc_set_default_external(utf8Encoding);
42
+
43
+ VALUE value = detail::to_ruby(std::string_view("Some String"));
44
+ Object object(value);
45
+ Object encoding = object.call("encoding");
46
+ Object encodingName = encoding.call("name");
47
+ ASSERT_EQUAL("UTF-8", detail::From_Ruby<std::string_view>().convert(encodingName));
48
+
49
+ rb_enc_set_default_external(rb_enc_from_encoding(defaultEncoding));
50
+ }
51
+
52
+ TESTCASE(std_string_view_from_ruby)
53
+ {
54
+ ASSERT_EQUAL(std::string_view(""), detail::From_Ruby<std::string_view>().convert(rb_str_new2("")));
55
+ ASSERT_EQUAL(std::string_view("foo"), detail::From_Ruby<std::string_view>().convert(rb_str_new2("foo")));
56
+
57
+ ASSERT_EXCEPTION_CHECK(
58
+ Exception,
59
+ detail::From_Ruby<std::string_view>().convert(rb_float_new(15.512)),
60
+ ASSERT_EQUAL("wrong argument type Float (expected String)", ex.what())
61
+ );
62
+ }
63
+
64
+ TESTCASE(std_string_view_to_ruby_with_binary)
65
+ {
66
+ Rice::String got = detail::to_ruby(std::string_view("\000test", 5));
67
+
68
+ ASSERT_EQUAL(String(std::string_view("\000test", 5)), got);
69
+ ASSERT_EQUAL(5ul, got.length());
70
+ }
71
+
72
+ TESTCASE(std_string_view_from_ruby_with_binary)
73
+ {
74
+ std::string_view got = detail::From_Ruby<std::string_view>().convert(rb_str_new("\000test", 5));
75
+ ASSERT_EQUAL(5ul, got.length());
76
+ ASSERT_EQUAL(std::string_view("\000test", 5), got);
77
+ }
78
+
79
+ TESTCASE(std_string_view_from_ruby_refefence)
80
+ {
81
+ VALUE value = rb_str_new("test", 4);
82
+ std::string_view view = detail::From_Ruby<std::string_view>().convert(value);
83
+ ASSERT_EQUAL("test", view);
84
+
85
+ String string(value);
86
+ string.instance_eval("self[1] = 'a'");
87
+ //ASSERT_EQUAL("tast", view);
88
+ }