summaryrefslogtreecommitdiffhomepage
path: root/cmd/mfmt/main_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/mfmt/main_test.go')
-rw-r--r--cmd/mfmt/main_test.go108
1 files changed, 108 insertions, 0 deletions
diff --git a/cmd/mfmt/main_test.go b/cmd/mfmt/main_test.go
new file mode 100644
index 0000000..72e3665
--- /dev/null
+++ b/cmd/mfmt/main_test.go
@@ -0,0 +1,108 @@
+package main
+
+import (
+ "bytes"
+ "testing"
+)
+
+func runTest(t *testing.T, in, out string, nilErr bool) {
+ r := bytes.NewReader([]byte(in))
+ w := new(bytes.Buffer)
+
+ err := mfmt("-", r, w)
+ if nilErr && err != nil {
+ t.Fatalf(`Expected err=nil; got "%s"`, err)
+ } else if !nilErr && err == nil {
+ t.Fatalf(`Expected err=Error; got nil`)
+ }
+
+ if nilErr && w.String() != out {
+ t.Fatalf(`Expected w.String()="%s"; got "%s"`, out, w.String())
+ }
+}
+
+func TestSpacing(t *testing.T) {
+ in := `
+ BEGIN 2002
+ BEGIN CIRC
+
+
+378.383.000 326.439.000 217.031.000 441.621.000 203.388.000 169.088.000 223.544.000 196.438.000
+
+
+ 10.817.950 118.526.000 ? 43.859.072 50.913.200 9.074.200 150.000 4.679.500
+`
+ out := `BEGIN 2002
+
+BEGIN CIRC
+378.383.000 326.439.000 217.031.000 441.621.000 203.388.000 169.088.000 223.544.000 196.438.000
+ 10.817.950 118.526.000 ? 43.859.072 50.913.200 9.074.200 150.000 4.679.500
+`
+ runTest(t, in, out, true)
+}
+
+func TestAddDots(t *testing.T) {
+ in := `BEGIN 2002
+
+BEGIN CIRC
+378383000 326439000 217031000 441621000 203388000 169088000 223544000 196438000
+ 10817950 118526000 ? 43859072 50913200 9074200 150000 4679500
+`
+ out := `BEGIN 2002
+
+BEGIN CIRC
+378.383.000 326.439.000 217.031.000 441.621.000 203.388.000 169.088.000 223.544.000 196.438.000
+ 10.817.950 118.526.000 ? 43.859.072 50.913.200 9.074.200 150.000 4.679.500
+`
+ runTest(t, in, out, true)
+}
+
+func TestComplete(t *testing.T) {
+ in := `
+ BEGIN 2002
+ BEGIN CIRC
+
+
+378383000 326439000 21703...1000 441621000 203388000 .1.6.9.0.8.8.0.0.0 223544000 196438000
+
+
+ 10817950 118526000 ? 43859072 50913200 9074..200 150000 4679500
+
+ BEGIN PROOF
+
+
+378383000 123456789 ..5 441621000 203388000 .1.6.9.0.8.8.0.0.0 223544000 196438000
+
+
+ 10817950 118526000 ? 43859072 50913200 9074..200 150000 4679500
+`
+ out := `BEGIN 2002
+
+BEGIN CIRC
+378.383.000 326.439.000 217.031.000 441.621.000 203.388.000 169.088.000 223.544.000 196.438.000
+ 10.817.950 118.526.000 ? 43.859.072 50.913.200 9.074.200 150.000 4.679.500
+
+BEGIN PROOF
+378.383.000 123.456.789 5 441.621.000 203.388.000 169.088.000 223.544.000 196.438.000
+ 10.817.950 118.526.000 ? 43.859.072 50.913.200 9.074.200 150.000 4.679.500
+`
+ runTest(t, in, out, true)
+}
+
+func TestLabelAlignment(t *testing.T) {
+ in := `BEGIN 2002
+
+BEGIN CIRC
+378383000 326439000 217031000 441621000 203388000 169088000 223544000 196438000
+KNM*: 10817950 118526000 ? 43859072 50913200 9074200 150000 4679500
+MdP: 115.000.000 156.400.000 89.300.000 5.200.000 54.800.000 3.100.000 2.600.000 2.500.000
+`
+ out := `BEGIN 2002
+
+BEGIN CIRC
+ 378.383.000 326.439.000 217.031.000 441.621.000 203.388.000 169.088.000 223.544.000 196.438.000
+KNM*: 10.817.950 118.526.000 ? 43.859.072 50.913.200 9.074.200 150.000 4.679.500
+MdP: 115.000.000 156.400.000 89.300.000 5.200.000 54.800.000 3.100.000 2.600.000 2.500.000
+`
+ runTest(t, in, out, true)
+}