-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new datatype: xml + improvements to
pretty
- Loading branch information
Showing
53 changed files
with
714 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package pretty | ||
|
||
import ( | ||
"testing" | ||
|
||
_ "github.com/lmorg/murex/builtins/types/generic" | ||
_ "github.com/lmorg/murex/builtins/types/json" | ||
"github.com/lmorg/murex/lang/types" | ||
"github.com/lmorg/murex/test" | ||
) | ||
|
||
func TestPrettyDefault(t *testing.T) { | ||
input := `{"foo":"bar"}` | ||
output := "{\n \"foo\": \"bar\"\n}" | ||
|
||
test.RunMethodTest(t, cmdPretty, "pretty", input, types.Json, []string{}, output, nil) | ||
test.RunMethodTest(t, cmdPretty, "pretty", input, types.Generic, []string{}, output, nil) | ||
} | ||
|
||
func TestPrettyStrict(t *testing.T) { | ||
input := `{"foo":"bar"}` | ||
output := "{\n \"foo\": \"bar\"\n}" | ||
|
||
test.RunMethodTest(t, cmdPretty, "pretty", input, types.Json, []string{"--strict"}, output, nil) | ||
test.RunMethodTest(t, cmdPretty, "pretty", input, types.Generic, []string{"--strict"}, input, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,52 @@ | ||
package pretty | ||
package pretty_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
_ "github.com/lmorg/murex/builtins/types/generic" | ||
_ "github.com/lmorg/murex/builtins/types/json" | ||
"github.com/lmorg/murex/lang/types" | ||
_ "github.com/lmorg/murex/builtins" | ||
"github.com/lmorg/murex/test" | ||
) | ||
|
||
func TestPrettyDefault(t *testing.T) { | ||
input := `{"foo":"bar"}` | ||
output := "{\n \"foo\": \"bar\"\n}" | ||
const ( | ||
svgPretty = ` | ||
<svg aria-label="Version: 6.3.4247" height="20" role="img" width="122" xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"> | ||
<clipPath id="r"> | ||
<rect fill="#fff" height="20" rx="3" width="122"/> | ||
</clipPath> | ||
<g clip-path="url(#r)"> | ||
<rect fill="#555" height="20" width="51"/> | ||
<rect fill="#2ea44f" height="20" width="71" x="51"/> | ||
<rect fill="url(#s)" height="20" width="122"/> | ||
</g> | ||
<g fill="#fff" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="110" text-anchor="middle" text-rendering="geometricPrecision"> | ||
<text aria-hidden="true" fill="#010101" fill-opacity="0.3" textLength="410" transform="scale(.1)" x="265" y="150">Version</text> | ||
<text fill="#fff" textLength="410" transform="scale(.1)" x="265" y="140">Version</text> | ||
<text aria-hidden="true" fill="#010101" fill-opacity="0.3" textLength="610" transform="scale(.1)" x="855" y="150">6.3.4247</text> | ||
<text fill="#fff" textLength="610" transform="scale(.1)" x="855" y="140">6.3.4247</text> | ||
</g> | ||
<linearGradient id="s" x2="0" y2="100%"> | ||
<stop offset="0" stop-color="#bbb" stop-opacity="0.1"/> | ||
<stop offset="1" stop-opacity="0.1"/> | ||
</linearGradient> | ||
<title>Version: 6.3.4247</title> | ||
</svg>` | ||
|
||
test.RunMethodTest(t, cmdPretty, "pretty", input, types.Json, []string{}, output, nil) | ||
test.RunMethodTest(t, cmdPretty, "pretty", input, types.Generic, []string{}, output, nil) | ||
} | ||
svgMinified = `<svg aria-label="Version: 6.3.4247" height="20" role="img" width="122" xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><clipPath id="r"><rect fill="#fff" height="20" rx="3" width="122"/></clipPath><g clip-path="url(#r)"><rect fill="#555" height="20" width="51"/><rect fill="#2ea44f" height="20" width="71" x="51"/><rect fill="url(#s)" height="20" width="122"/></g><g fill="#fff" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="110" text-anchor="middle" text-rendering="geometricPrecision"><text aria-hidden="true" fill="#010101" fill-opacity="0.3" textLength="410" transform="scale(.1)" x="265" y="150">Version</text><text fill="#fff" textLength="410" transform="scale(.1)" x="265" y="140">Version</text><text aria-hidden="true" fill="#010101" fill-opacity="0.3" textLength="610" transform="scale(.1)" x="855" y="150">6.3.4247</text><text fill="#fff" textLength="610" transform="scale(.1)" x="855" y="140">6.3.4247</text></g><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity="0.1"/><stop offset="1" stop-opacity="0.1"/></linearGradient><title>Version: 6.3.4247</title></svg>` | ||
) | ||
|
||
func TestPrettyStrict(t *testing.T) { | ||
input := `{"foo":"bar"}` | ||
output := "{\n \"foo\": \"bar\"\n}" | ||
func TestMarshallers(t *testing.T) { | ||
tests := []test.MurexTest{ | ||
{ | ||
Block: fmt.Sprintf(`%%(%s) -> :xml: format json -> format xml`, svgMinified), | ||
Stdout: strings.TrimSpace(svgMinified), | ||
}, | ||
{ | ||
Block: fmt.Sprintf(`%%(%s) -> :xml: format json -> format xml -> pretty`, svgMinified), | ||
Stdout: strings.TrimSpace(svgPretty), | ||
}, | ||
} | ||
|
||
test.RunMethodTest(t, cmdPretty, "pretty", input, types.Json, []string{"--strict"}, output, nil) | ||
test.RunMethodTest(t, cmdPretty, "pretty", input, types.Generic, []string{"--strict"}, input, nil) | ||
test.RunMurexTests(tests, t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
- application/x-csv | ||
- text/csv | ||
- text/x-csv | ||
- +csv | ||
Extensions: | ||
- csv | ||
Synonyms: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ | |
- application/x-json | ||
- text/json | ||
- text/x-json | ||
- +json | ||
Extensions: | ||
- json | ||
Related: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ | |
- application/x-toml | ||
- text/toml | ||
- text/x-toml | ||
- +toml | ||
Extensions: | ||
- toml | ||
Related: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package xml | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/lmorg/murex/lang" | ||
"github.com/lmorg/murex/lang/stdio" | ||
) | ||
|
||
func readArray(ctx context.Context, read stdio.Io, callback func([]byte)) error { | ||
// Create a marshaller function to pass to ArrayTemplate | ||
marshaller := func(v interface{}) ([]byte, error) { | ||
return MarshalTTY(v, read.IsTTY()) | ||
} | ||
|
||
return lang.ArrayTemplate(ctx, marshaller, unmarshaller, read, callback) | ||
} |
Oops, something went wrong.