/
resolve_message_reference.rs
60 lines (47 loc) · 1.23 KB
/
resolve_message_reference.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
extern crate fluent;
use self::fluent::context::MessageContext;
#[test]
fn message_reference() {
let mut ctx = MessageContext::new("x-testing");
ctx.add_messages(
"
foo = Foo
bar = { foo } Bar
",
);
let value = ctx.get_message("bar").and_then(|msg| ctx.format(msg, None));
assert_eq!(value, Some("Foo Bar".to_string()));
}
#[test]
fn message_reference_nested() {
let mut ctx = MessageContext::new("x-testing");
ctx.add_messages(
"
foo = Foo
bar = { foo } Bar
baz = { bar } Baz
",
);
let value = ctx.get_message("baz").and_then(|msg| ctx.format(msg, None));
assert_eq!(value, Some("Foo Bar Baz".to_string()));
}
#[test]
fn message_reference_missing() {
let mut ctx = MessageContext::new("x-testing");
ctx.add_messages("bar = { foo } Bar");
let value = ctx.get_message("bar").and_then(|msg| ctx.format(msg, None));
assert_eq!(value, Some("___ Bar".to_string()));
}
#[test]
#[ignore]
fn message_reference_cyclic() {
let mut ctx = MessageContext::new("x-testing");
ctx.add_messages(
"
foo = Foo { bar }
bar = { foo } Bar
",
);
let value = ctx.get_message("foo").and_then(|msg| ctx.format(msg, None));
assert_eq!(value, Some("Foo ___".to_string()));
}