2020-03-20 20:35:09 +01:00
|
|
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
2023-02-13 13:42:08 +01:00
|
|
|
use nu_test_support::nu_with_plugins;
|
2020-03-20 20:35:09 +01:00
|
|
|
use nu_test_support::playground::Playground;
|
2023-04-08 20:52:37 +02:00
|
|
|
use pretty_assertions::assert_eq;
|
2020-03-20 20:35:09 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn infers_types() {
|
|
|
|
Playground::setup("filter_from_vcf_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"contacts.vcf",
|
2023-07-12 00:00:31 +02:00
|
|
|
r"
|
2020-03-20 20:35:09 +01:00
|
|
|
BEGIN:VCARD
|
|
|
|
VERSION:3.0
|
|
|
|
FN:John Doe
|
|
|
|
N:Doe;John;;;
|
|
|
|
EMAIL;TYPE=INTERNET:john.doe99@gmail.com
|
|
|
|
item1.ORG:'Alpine Ski Resort'
|
|
|
|
item1.X-ABLabel:Other
|
|
|
|
item2.TITLE:'Ski Instructor'
|
|
|
|
item2.X-ABLabel:Other
|
|
|
|
BDAY:19001106
|
|
|
|
NOTE:Facebook: john.doe.3\nWebsite: \nHometown: Cleveland\, Ohio
|
|
|
|
CATEGORIES:myContacts
|
|
|
|
END:VCARD
|
|
|
|
BEGIN:VCARD
|
|
|
|
VERSION:3.0
|
|
|
|
FN:Alex Smith
|
|
|
|
N:Smith;Alex;;;
|
|
|
|
TEL;TYPE=CELL:(890) 123-4567
|
|
|
|
CATEGORIES:Band,myContacts
|
|
|
|
END:VCARD
|
2023-07-12 00:00:31 +02:00
|
|
|
",
|
2020-03-20 20:35:09 +01:00
|
|
|
)]);
|
|
|
|
|
2023-02-13 13:42:08 +01:00
|
|
|
let cwd = dirs.test();
|
|
|
|
let actual = nu_with_plugins!(
|
|
|
|
cwd: cwd,
|
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open contacts.vcf | length"
|
|
|
|
);
|
2020-03-20 20:35:09 +01:00
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "2");
|
2020-03-20 20:35:09 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_vcf_text_to_table() {
|
|
|
|
Playground::setup("filter_from_vcf_test_2", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"contacts.txt",
|
2023-07-12 00:00:31 +02:00
|
|
|
r"
|
2020-03-20 20:35:09 +01:00
|
|
|
BEGIN:VCARD
|
|
|
|
VERSION:3.0
|
|
|
|
FN:John Doe
|
|
|
|
N:Doe;John;;;
|
|
|
|
EMAIL;TYPE=INTERNET:john.doe99@gmail.com
|
|
|
|
item1.ORG:'Alpine Ski Resort'
|
|
|
|
item1.X-ABLabel:Other
|
|
|
|
item2.TITLE:'Ski Instructor'
|
|
|
|
item2.X-ABLabel:Other
|
|
|
|
BDAY:19001106
|
|
|
|
NOTE:Facebook: john.doe.3\nWebsite: \nHometown: Cleveland\, Ohio
|
|
|
|
CATEGORIES:myContacts
|
|
|
|
END:VCARD
|
2023-07-12 00:00:31 +02:00
|
|
|
",
|
2020-03-20 20:35:09 +01:00
|
|
|
)]);
|
|
|
|
|
2023-02-13 13:42:08 +01:00
|
|
|
let cwd = dirs.test();
|
|
|
|
let actual = nu_with_plugins!(
|
|
|
|
cwd: cwd,
|
|
|
|
plugin: ("nu_plugin_formats"),
|
2020-03-20 20:35:09 +01:00
|
|
|
r#"
|
|
|
|
open contacts.txt
|
2020-05-04 10:44:33 +02:00
|
|
|
| from vcf
|
2022-02-04 03:01:45 +01:00
|
|
|
| get properties.0
|
2020-03-20 20:35:09 +01:00
|
|
|
| where name == "EMAIL"
|
|
|
|
| first
|
|
|
|
| get value
|
|
|
|
"#
|
2023-02-13 13:42:08 +01:00
|
|
|
);
|
2020-03-20 20:35:09 +01:00
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "john.doe99@gmail.com");
|
2020-03-20 20:35:09 +01:00
|
|
|
})
|
|
|
|
}
|