aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe/tests/io/buffer_io_test.rs27
-rw-r--r--crates/shirabe/tests/io/main.rs1
-rw-r--r--crates/shirabe/tests/json/json_validation_exception_test.rs24
-rw-r--r--crates/shirabe/tests/json/main.rs1
-rw-r--r--crates/shirabe/tests/platform/main.rs1
-rw-r--r--crates/shirabe/tests/platform/runtime_test.rs25
6 files changed, 79 insertions, 0 deletions
diff --git a/crates/shirabe/tests/io/buffer_io_test.rs b/crates/shirabe/tests/io/buffer_io_test.rs
index c3e9876..67e6ab4 100644
--- a/crates/shirabe/tests/io/buffer_io_test.rs
+++ b/crates/shirabe/tests/io/buffer_io_test.rs
@@ -1 +1,28 @@
//! ref: composer/tests/Composer/Test/IO/BufferIOTest.php
+
+use shirabe::io::buffer_io::BufferIO;
+use shirabe::io::IOInterfaceImmutable;
+use shirabe_external_packages::symfony::console::output::output_interface::VERBOSITY_NORMAL;
+use shirabe_php_shim::PhpMixed;
+
+#[test]
+#[ignore = "BufferIO::set_user_inputs is todo!() (needs StreamableInputInterface downcast wiring)"]
+fn test_set_user_inputs() {
+ let mut buffer_io = BufferIO::new(String::new(), VERBOSITY_NORMAL, None).unwrap();
+
+ // The Rust port always uses a StreamableInputInterface, so the version-guard
+ // exception branch in the original test does not apply.
+ buffer_io
+ .set_user_inputs(vec!["yes".to_string(), "no".to_string(), String::new()])
+ .unwrap();
+
+ assert!(buffer_io.ask_confirmation("Please say yes!".to_string(), false));
+ assert!(!buffer_io.ask_confirmation("Now please say no!".to_string(), true));
+ assert_eq!(
+ PhpMixed::String("default".to_string()),
+ buffer_io.ask(
+ "Empty string last".to_string(),
+ PhpMixed::String("default".to_string())
+ )
+ );
+}
diff --git a/crates/shirabe/tests/io/main.rs b/crates/shirabe/tests/io/main.rs
new file mode 100644
index 0000000..00f19c8
--- /dev/null
+++ b/crates/shirabe/tests/io/main.rs
@@ -0,0 +1 @@
+mod buffer_io_test;
diff --git a/crates/shirabe/tests/json/json_validation_exception_test.rs b/crates/shirabe/tests/json/json_validation_exception_test.rs
index 12620ba..271ca9b 100644
--- a/crates/shirabe/tests/json/json_validation_exception_test.rs
+++ b/crates/shirabe/tests/json/json_validation_exception_test.rs
@@ -1 +1,25 @@
//! ref: composer/tests/Composer/Test/Json/JsonValidationExceptionTest.php
+
+use shirabe::json::json_validation_exception::JsonValidationException;
+
+#[test]
+fn test_get_errors() {
+ for (message, errors, expected_message, expected_errors) in error_provider() {
+ let object = JsonValidationException::new(message.to_string(), errors.clone());
+ assert_eq!(expected_message, object.get_message());
+ assert_eq!(&expected_errors, object.get_errors());
+ }
+}
+
+#[test]
+fn test_get_errors_when_no_errors_provided() {
+ let object = JsonValidationException::new("test message".to_string(), vec![]);
+ assert_eq!(&Vec::<String>::new(), object.get_errors());
+}
+
+fn error_provider() -> Vec<(&'static str, Vec<String>, &'static str, Vec<String>)> {
+ vec![
+ ("test message", vec![], "test message", vec![]),
+ ("", vec!["foo".to_string()], "", vec!["foo".to_string()]),
+ ]
+}
diff --git a/crates/shirabe/tests/json/main.rs b/crates/shirabe/tests/json/main.rs
new file mode 100644
index 0000000..a98ebc5
--- /dev/null
+++ b/crates/shirabe/tests/json/main.rs
@@ -0,0 +1 @@
+mod json_validation_exception_test;
diff --git a/crates/shirabe/tests/platform/main.rs b/crates/shirabe/tests/platform/main.rs
new file mode 100644
index 0000000..a43e54a
--- /dev/null
+++ b/crates/shirabe/tests/platform/main.rs
@@ -0,0 +1 @@
+mod runtime_test;
diff --git a/crates/shirabe/tests/platform/runtime_test.rs b/crates/shirabe/tests/platform/runtime_test.rs
index 1fbb628..a655c95 100644
--- a/crates/shirabe/tests/platform/runtime_test.rs
+++ b/crates/shirabe/tests/platform/runtime_test.rs
@@ -1 +1,26 @@
//! ref: composer/tests/Composer/Test/Platform/RuntimeTest.php
+
+use shirabe::platform::runtime::Runtime;
+
+#[test]
+#[ignore = "Runtime::parse_html_extension_info reaches a todo!() in the php-shim (html_entity_decode)"]
+fn test_parse_extension_info() {
+ for (html_input, expected_output) in provide_extension_infos() {
+ assert_eq!(expected_output, Runtime::parse_html_extension_info(html_input));
+ }
+}
+
+fn provide_extension_infos() -> Vec<(&'static str, &'static str)> {
+ vec![(
+ // 'pdo_sqlite'
+ "<h2><a name=\"module_pdo_sqlite\" href=\"#module_pdo_sqlite\">pdo_sqlite</a></h2>
+<table>
+<tr><td class=\"e\">PDO Driver for SQLite 3.x </td><td class=\"v\">enabled </td></tr>
+<tr><td class=\"e\">SQLite Library </td><td class=\"v\">3.40.1 </td></tr>
+</table>",
+ "pdo_sqlite
+
+PDO Driver for SQLite 3.x => enabled
+SQLite Library => 3.40.1",
+ )]
+}