Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tests of idna to serde-json #518

Merged
merged 1 commit into from Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion idna/Cargo.toml
Expand Up @@ -20,7 +20,7 @@ name = "unit"

[dev-dependencies]
rustc-test = "0.3"
rustc-serialize = "0.3"
serde_json = "1.0"

[dependencies]
unicode-bidi = "0.3"
Expand Down
14 changes: 8 additions & 6 deletions idna/tests/punycode.rs
Expand Up @@ -7,7 +7,9 @@
// except according to those terms.

use idna::punycode::{decode, encode_str};
use rustc_serialize::json::{Json, Object};
use serde_json::Value;
use serde_json::map::Map;
use std::str::FromStr;
use test::TestFn;

fn one_test(decoded: &str, encoded: &str) {
Expand Down Expand Up @@ -37,20 +39,20 @@ fn one_test(decoded: &str, encoded: &str) {
}
}

fn get_string<'a>(map: &'a Object, key: &str) -> &'a str {
fn get_string<'a>(map: &'a Map<String, Value>, key: &str) -> &'a str {
match map.get(&key.to_string()) {
Some(&Json::String(ref s)) => s,
Some(&Value::String(ref s)) => s,
None => "",
_ => panic!(),
}
}

pub fn collect_tests<F: FnMut(String, TestFn)>(add_test: &mut F) {
match Json::from_str(include_str!("punycode_tests.json")) {
Ok(Json::Array(tests)) => {
match Value::from_str(include_str!("punycode_tests.json")) {
Ok(Value::Array(tests)) => {
for (i, test) in tests.into_iter().enumerate() {
match test {
Json::Object(o) => {
Value::Object(o) => {
let test_name = {
let desc = get_string(&o, "description");
if desc.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion idna/tests/tests.rs
@@ -1,5 +1,5 @@
extern crate idna;
extern crate rustc_serialize;
extern crate serde_json;
extern crate rustc_test as test;

mod punycode;
Expand Down