nushell/crates/nu-command/tests/commands/url/join.rs
Stefan Holderbach 7c1487e18d
Use int type name consistently (#10579)
# Description
When referring to the type use `int` consistently. Only when referring
to the concept of integer numbers use `integer`.

- Fix `random integer` to `random int` tests
  - Forgot in #10520
- Use int instead of integer in error messages
- Use int type name in bits commands
- Fix messages in `for` examples
- Use int typename in `into` commands
- Use int typename in rest of commands
- Report errors in `nu-protocol` with int typename

Work for #10332 

# User-Facing Changes
User errorrs should now use `int` so you can easily find the necessary
commands or type annotations.

# Tests + Formatting
Only two tests found that needed updating
2023-10-03 18:24:32 +02:00

349 lines
8.3 KiB
Rust

use nu_test_support::{nu, pipeline};
#[test]
fn url_join_simple() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "",
"password": "",
"host": "localhost",
"port": "",
} | url join
"#
));
assert_eq!(actual.out, "http://localhost");
}
#[test]
fn url_join_with_only_user() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "usr",
"password": "",
"host": "localhost",
"port": "",
} | url join
"#
));
assert_eq!(actual.out, "http://localhost");
}
#[test]
fn url_join_with_only_pwd() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "",
"password": "pwd",
"host": "localhost",
"port": "",
} | url join
"#
));
assert_eq!(actual.out, "http://localhost");
}
#[test]
fn url_join_with_user_and_pwd() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "usr",
"password": "pwd",
"host": "localhost",
"port": "",
} | url join
"#
));
assert_eq!(actual.out, "http://usr:pwd@localhost");
}
#[test]
fn url_join_with_query() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "usr",
"password": "pwd",
"host": "localhost",
"query": "par_1=aaa&par_2=bbb"
"port": "",
} | url join
"#
));
assert_eq!(actual.out, "http://usr:pwd@localhost?par_1=aaa&par_2=bbb");
}
#[test]
fn url_join_with_params() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "usr",
"password": "pwd",
"host": "localhost",
"params": {
"par_1": "aaa",
"par_2": "bbb"
},
"port": "1234",
} | url join
"#
));
assert_eq!(
actual.out,
"http://usr:pwd@localhost:1234?par_1=aaa&par_2=bbb"
);
}
#[test]
fn url_join_with_same_query_and_params() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "usr",
"password": "pwd",
"host": "localhost",
"query": "par_1=aaa&par_2=bbb",
"params": {
"par_1": "aaa",
"par_2": "bbb"
},
"port": "1234",
} | url join
"#
));
assert_eq!(
actual.out,
"http://usr:pwd@localhost:1234?par_1=aaa&par_2=bbb"
);
}
#[test]
fn url_join_with_different_query_and_params() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "usr",
"password": "pwd",
"host": "localhost",
"query": "par_1=aaa&par_2=bbb",
"params": {
"par_1": "aaab",
"par_2": "bbb"
},
"port": "1234",
} | url join
"#
));
assert!(actual
.err
.contains("Mismatch, qs from params is: ?par_1=aaab&par_2=bbb"));
assert!(actual
.err
.contains("instead query is: ?par_1=aaa&par_2=bbb"));
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "usr",
"password": "pwd",
"host": "localhost",
"params": {
"par_1": "aaab",
"par_2": "bbb"
},
"query": "par_1=aaa&par_2=bbb",
"port": "1234",
} | url join
"#
));
assert!(actual
.err
.contains("Mismatch, query param is: par_1=aaa&par_2=bbb"));
assert!(actual
.err
.contains("instead qs from params is: ?par_1=aaab&par_2=bbb"));
}
#[test]
fn url_join_with_invalid_params() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "usr",
"password": "pwd",
"host": "localhost",
"params": "aaa",
"port": "1234",
} | url join
"#
));
assert!(actual.err.contains("Key params has to be a record"));
}
#[test]
fn url_join_with_port() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"host": "localhost",
"port": "1234",
} | url join
"#
));
assert_eq!(actual.out, "http://localhost:1234");
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"host": "localhost",
"port": 1234,
} | url join
"#
));
assert_eq!(actual.out, "http://localhost:1234");
}
#[test]
fn url_join_with_invalid_port() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"host": "localhost",
"port": "aaaa",
} | url join
"#
));
assert!(actual
.err
.contains("Port parameter should represent an unsigned int"));
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"host": "localhost",
"port": [],
} | url join
"#
));
assert!(actual
.err
.contains("Port parameter should be an unsigned int or a string representing it"));
}
#[test]
fn url_join_with_missing_scheme() {
let actual = nu!(pipeline(
r#"
{
"host": "localhost"
} | url join
"#
));
assert!(actual.err.contains("missing parameter: scheme"));
}
#[test]
fn url_join_with_missing_host() {
let actual = nu!(pipeline(
r#"
{
"scheme": "https"
} | url join
"#
));
assert!(actual.err.contains("missing parameter: host"));
}
#[test]
fn url_join_with_fragment() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "usr",
"password": "pwd",
"host": "localhost",
"fragment": "frag",
"port": "1234",
} | url join
"#
));
assert_eq!(actual.out, "http://usr:pwd@localhost:1234#frag");
}
#[test]
fn url_join_with_fragment_and_params() {
let actual = nu!(pipeline(
r#"
{
"scheme": "http",
"username": "usr",
"password": "pwd",
"host": "localhost",
"params": {
"par_1": "aaa",
"par_2": "bbb"
},
"port": "1234",
"fragment": "frag"
} | url join
"#
));
assert_eq!(
actual.out,
"http://usr:pwd@localhost:1234?par_1=aaa&par_2=bbb#frag"
);
}
#[test]
fn url_join_with_empty_params() {
let actual = nu!(pipeline(
r#"
{
"scheme": "https",
"host": "localhost",
"path": "/foo",
"params": {}
} | url join
"#
));
assert_eq!(actual.out, "https://localhost/foo");
}