|
| 1 | +use pretty_assertions::assert_eq; |
| 2 | + |
| 3 | +use crate::{CommandExt, tool}; |
| 4 | + |
| 5 | +#[test] |
| 6 | +fn test_simple_geometries() { |
| 7 | + let input = b"\ |
| 8 | + POINT (0 0)\n\ |
| 9 | + LINESTRING (1 1, 2 2)\n\ |
| 10 | + POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))\n\ |
| 11 | + "; |
| 12 | + |
| 13 | + let expected = "\ |
| 14 | + <svg viewBox=\"-12 -12 26 26\" xmlns=\"http://www.w3.org/2000/svg\">\n\ |
| 15 | + <style type=\"text/css\">\n\ |
| 16 | + svg { stroke:black; stroke-width:2; fill:none; transform:scale(1,-1);}\n\ |
| 17 | + </style>\n\ |
| 18 | + <circle cx=\"-9\" cy=\"-9\" r=\"1\"/>\n\ |
| 19 | + <polyline points=\"1 1 11 11\"/>\n\ |
| 20 | + <path d=\"M-9,-9 L1,-9 L1,1 L-9,1 z\" fill-rule=\"evenodd\"/>\n\ |
| 21 | + </svg>\ |
| 22 | + "; |
| 23 | + |
| 24 | + let output = tool("wkt2svg") |
| 25 | + .arg("--scale=10") |
| 26 | + .write_stdin(input) |
| 27 | + .captured_output(); |
| 28 | + assert!(output.status.success()); |
| 29 | + let stdout = String::from_utf8_lossy(&output.stdout); |
| 30 | + assert_eq!(expected, stdout); |
| 31 | +} |
| 32 | + |
| 33 | +#[test] |
| 34 | +fn test_cli_styles() { |
| 35 | + let input = b"\ |
| 36 | + POINT (0 0)\n\ |
| 37 | + LINESTRING (1 1, 2 2)\n\ |
| 38 | + POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))\n\ |
| 39 | + "; |
| 40 | + |
| 41 | + let expected = "\ |
| 42 | + <svg viewBox=\"-12 -12 26 26\" xmlns=\"http://www.w3.org/2000/svg\">\n\ |
| 43 | + <style type=\"text/css\">\n\ |
| 44 | + svg {stroke-dasharray:5; stroke:red; stroke-width:2; fill:blue; transform:scale(1,-1);}\n\ |
| 45 | + </style>\n\ |
| 46 | + <circle cx=\"-9\" cy=\"-9\" r=\"0.5\"/>\n\ |
| 47 | + <polyline points=\"1 1 11 11\"/>\n\ |
| 48 | + <path d=\"M-9,-9 L1,-9 L1,1 L-9,1 z\" fill-rule=\"evenodd\"/>\n\ |
| 49 | + </svg>\ |
| 50 | + "; |
| 51 | + |
| 52 | + let output = tool("wkt2svg") |
| 53 | + .arg("--scale=10") |
| 54 | + .arg("--point-radius=0.5") |
| 55 | + .arg("--stroke=red") |
| 56 | + .arg("--stroke-dasharray=5") |
| 57 | + .arg("--fill=blue") |
| 58 | + .write_stdin(input) |
| 59 | + .captured_output(); |
| 60 | + assert!(output.status.success()); |
| 61 | + let stdout = String::from_utf8_lossy(&output.stdout); |
| 62 | + assert_eq!(expected, stdout); |
| 63 | +} |
| 64 | + |
| 65 | +#[test] |
| 66 | +fn test_wkt_styles() { |
| 67 | + let input = b"\ |
| 68 | + POINT(0 0)\n\ |
| 69 | + POINT(100 100)\n\ |
| 70 | + STROKEWIDTH(4)\n\ |
| 71 | + STROKEDASHARRAY(6 1)\n\ |
| 72 | + POINTRADIUS(20)\n\ |
| 73 | + FILL(red)\n\ |
| 74 | + POINT(50 50)\n\ |
| 75 | + "; |
| 76 | + |
| 77 | + let expected = "\ |
| 78 | + <svg viewBox=\"-453 -453 1006 1006\" xmlns=\"http://www.w3.org/2000/svg\">\n\ |
| 79 | + <style type=\"text/css\">\n\ |
| 80 | + svg { stroke:black; stroke-width:2; fill:none; transform:scale(1,-1);}\n\ |
| 81 | + </style>\n\ |
| 82 | + <circle cx=\"-450\" cy=\"-450\" r=\"1\"/>\n\ |
| 83 | + <circle cx=\"550\" cy=\"550\" r=\"1\"/>\n\ |
| 84 | + <circle cx=\"50\" cy=\"50\" fill=\"red\" r=\"20\" stroke-dasharray=\"6 1\" stroke-width=\"4\"/>\n\ |
| 85 | + </svg>\ |
| 86 | + "; |
| 87 | + |
| 88 | + let output = tool("wkt2svg") |
| 89 | + .arg("--scale=10") |
| 90 | + .write_stdin(input) |
| 91 | + .captured_output(); |
| 92 | + assert!(output.status.success()); |
| 93 | + let stdout = String::from_utf8_lossy(&output.stdout); |
| 94 | + assert_eq!(expected, stdout); |
| 95 | +} |
0 commit comments