File: getters.rs

package info (click to toggle)
rust-gettext-rs 0.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 176 kB
  • sloc: makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,777 bytes parent folder | download
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
61
62
63
64
65
66
67
extern crate gettextrs;
#[macro_use]
extern crate lazy_static;

use gettextrs::{getters::*, *};
use std::sync::Mutex;

lazy_static! {
    // "Current text domain" is a global resource which all tests modify. This mutex serializes
    // access to that resource.
    static ref TEXTDOMAIN_MUTEX: Mutex<()> = Mutex::new(());
}

#[test]
fn test_current_textdomain() {
    let _lock = TEXTDOMAIN_MUTEX.lock().unwrap();

    textdomain("just_testing").unwrap();
    assert_eq!(current_textdomain().unwrap(), "just_testing".as_bytes());

    textdomain("test_current_textdomain").unwrap();
    assert_eq!(
        current_textdomain().unwrap(),
        "test_current_textdomain".as_bytes()
    );
}

#[test]
fn test_domain_directory() {
    use std::path::PathBuf;

    static TEXTDOMAIN: &'static str = "test_domain_directory";

    {
        let _lock = TEXTDOMAIN_MUTEX.lock().unwrap();
        textdomain(TEXTDOMAIN).unwrap();
    }

    bindtextdomain(TEXTDOMAIN, "/tmp").unwrap();
    assert_eq!(domain_directory(TEXTDOMAIN).unwrap(), PathBuf::from("/tmp"));

    let path = "/some/nonexistent path (hopefully)";
    bindtextdomain(TEXTDOMAIN, path).unwrap();
    assert_eq!(domain_directory(TEXTDOMAIN).unwrap(), PathBuf::from(path));
}

#[test]
fn test_textdomain_codeset() {
    static TEXTDOMAIN: &'static str = "test_textdomain_codeset";

    {
        let _lock = TEXTDOMAIN_MUTEX.lock().unwrap();
        textdomain(TEXTDOMAIN).unwrap();
    }

    bind_textdomain_codeset(TEXTDOMAIN, "C").unwrap();
    assert_eq!(
        textdomain_codeset(TEXTDOMAIN).unwrap(),
        Some("C".to_string())
    );

    bind_textdomain_codeset(TEXTDOMAIN, "UTF-8").unwrap();
    assert_eq!(
        textdomain_codeset(TEXTDOMAIN).unwrap(),
        Some("UTF-8".to_string())
    );
}