summaryrefslogtreecommitdiffstats
path: root/packages/svgbob/tests/simple_shapes.rs
blob: 3313c506dbf7e49c52cf3c9c1f38f06f3eec7ca8 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use svgbob::Settings;

#[test]
fn rect1() {
    let bob = r#"
    +----------+
    |          |
    +----------+
    "#;

    let expected = r#"<svg xmlns="http://www.w3.org/2000/svg" width="136" height="80">
  <rect x="36" y="24" width="88" height="32" class="solid nofill" rx="0"></rect>
</svg>"#;

    let svg = svgbob::to_svg_with_settings(bob, &Settings::for_debug());
    println!("{}", svg);
    assert_eq!(expected, svg);
}

#[test]
fn escaped_shape() {
    let bob = r#"
    "+----------+"
    "|          |"
    "+----------+"
    "#;

    let expected = r#"<svg xmlns="http://www.w3.org/2000/svg" width="16" height="32">
  <text x="34" y="28" >+----------+</text>
  <text x="34" y="44" >|          |</text>
  <text x="34" y="60" >+----------+</text>
</svg>"#;

    let svg = svgbob::to_svg_with_settings(bob, &Settings::for_debug());
    println!("{}", svg);
    assert_eq!(expected, svg);
}

#[test]
fn rounded_rect() {
    let bob = r#"
    .----------.
    |          |
    '----------'
    "#;

    let expected = r#"<svg xmlns="http://www.w3.org/2000/svg" width="136" height="80">
  <rect x="36" y="24" width="88" height="32" class="solid nofill" rx="4"></rect>
</svg>"#;

    let svg = svgbob::to_svg_with_settings(bob, &Settings::for_debug());
    println!("{}", svg);
    assert_eq!(expected, svg);
}

#[test]
fn just_v() {
    let bob = r#"
        V
    "#;

    let expected = r#"<svg xmlns="http://www.w3.org/2000/svg" width="80" height="48">
  <text x="66" y="28" >V</text>
</svg>"#;

    let svg = svgbob::to_svg_with_settings(bob, &Settings::for_debug());
    println!("{}", svg);
    assert_eq!(expected, svg);
}

#[test]
fn arrow_down() {
    let bob = r#"
        |
        V
    "#;

    let expected = r#"<svg xmlns="http://www.w3.org/2000/svg" width="80" height="64">
  <line x1="68" y1="16" x2="68" y2="36" class="solid"></line>
  <polygon points="64,36 72,36 68,48" class="filled"></polygon>
</svg>"#;

    let svg = svgbob::to_svg_with_settings(bob, &Settings::for_debug());
    println!("{}", svg);
    assert_eq!(expected, svg);
}