Skip to content

Commit

Permalink
Stabilize parsers output by sorting hash keys (fix #29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Afanasyev committed Aug 25, 2016
1 parent 00ca5c8 commit a6c4d3f
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion lib/Serge/Engine/Plugin/parse_json.pm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ sub process_node {
if (ref($subtree) eq 'HASH') {
# hash

foreach my $key (keys %$subtree) {
foreach my $key (sort keys %$subtree) {
$self->process_node($path.'/'.$key, $subtree->{$key}, $callbackref, $lang, $subtree, $key);
}
} elsif (ref($subtree) eq 'ARRAY') {
Expand Down
4 changes: 2 additions & 2 deletions lib/Serge/Engine/Plugin/parse_yaml.pm
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ sub parse {

if ($is_rails) {
my @tree_keys = keys %$tree;
my $tree_count = int @tree_keys;
my $tree_count = @tree_keys;
if ($tree_count == 0) {
# Special case NOOP. Empty data
} elsif ($tree_count == 1) {
Expand Down Expand Up @@ -187,7 +187,7 @@ sub process_node {
if (ref($subtree) eq 'HASH') {
# hash

foreach my $key (keys %$subtree) {
foreach my $key (sort keys %$subtree) {
$self->process_node($path.'/'.$key, $subtree->{$key}, $callbackref, $lang, $subtree, $key);
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions t/data/engine/parse_yaml/00/reference-output/database/items
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
items
{
0 1 3 1 1 /foo__PRESERVE_ANCHOR__foo_anchor NO 0
1 2 5 1 2 /subsection1/baz NO 0
2 3 7 1 3 /subsection1/foo NO 0
3 4 9 1 4 /baz__PRESERVE_ANCHOR__baz_anchor NO 0
0 1 3 1 1 /baz__PRESERVE_ANCHOR__baz_anchor NO 0
1 2 5 1 2 /foo__PRESERVE_ANCHOR__foo_anchor NO 0
2 3 7 1 3 /subsection1/baz NO 0
3 4 9 1 4 /subsection1/foo NO 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ properties
3 4 items:1 1,2,3,4
4 5 ts:1:test:count 4
5 6 usn:1:test 13
6 7 ts:1:test 662ff31deeaa4f8810940407f3ee7903
6 7 ts:1:test c3d6d7fab038c93e363a8f9ec416ae09
7 8 target:1:test_job:test 6c11ff4063c36de7c89d21fd7e4feceb
8 9 target:mtime:1:test_job:test 12345678
9 10 source:1:test_job:test 9cc74248d8061fa6f550c68594c2abbf
10 11 source:ts:1:test_job:test
662ff31deeaa4f8810940407f3ee7903
c3d6d7fab038c93e363a8f9ec416ae09
11 12 job-hash:test_namespace:test_job
58a891737cbc1baf5d60e0c52f2263b5
12 13 job-plugin:test_namespace:test_job parse_yaml.
Expand Down
8 changes: 4 additions & 4 deletions t/data/engine/parse_yaml/00/reference-output/database/strings
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
strings
{
0 1 2 bar1 NO 0
1 2 4 etc2 NO 0
2 3 6 bar2 NO 0
3 4 8 etc1 NO 0
0 1 2 etc1 NO 0
1 2 4 bar1 NO 0
2 3 6 etc2 NO 0
3 4 8 bar2 NO 0
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
translations
{
0 1 10 1 test ḃáŕ1 NO 0 0
1 2 11 2 test ēţç2 NO 0 0
2 3 12 3 test ḃáŕ2 NO 0 0
3 4 13 4 test ēţç1 NO 0 0
0 1 10 1 test ēţç1 NO 0 0
1 2 11 2 test ḃáŕ1 NO 0 0
2 3 12 3 test ēţç2 NO 0 0
3 4 13 4 test ḃáŕ2 NO 0 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ msgstr ""
"Language: test\n"
"Generated-By: Serge 1.1\n"

#. /baz__PRESERVE_ANCHOR__baz_anchor
#: File: strings.yml
#: ID: 641460c2a4284dfe0a6e9b1368f89fd5
msgid "etc1"
msgstr "ēţç1"

#. /foo__PRESERVE_ANCHOR__foo_anchor
#: File: strings.yml
#: ID: 2b2b5146df00a72b24a62de7f60c818b
Expand All @@ -22,9 +28,3 @@ msgstr "ēţç2"
#: ID: e5f2adbdbe00c558062db891f2072489
msgid "bar2"
msgstr "ḃáŕ2"

#. /baz__PRESERVE_ANCHOR__baz_anchor
#: File: strings.yml
#: ID: 641460c2a4284dfe0a6e9b1368f89fd5
msgid "etc1"
msgstr "ēţç1"
12 changes: 6 additions & 6 deletions t/data/engine/parse_yaml/01/reference-output/database/items
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
items
{
0 1 3 1 1 /subsection1/baz NO 0
1 2 5 1 2 /subsection1/foo NO 0
2 3 7 1 3 /baz NO 0
3 4 9 1 4 /subsection2/baz NO 0
4 5 11 1 5 /subsection2/foo NO 0
5 6 13 1 6 /foo NO 0
0 1 3 1 1 /baz NO 0
1 2 5 1 2 /foo NO 0
2 3 7 1 3 /subsection1/baz NO 0
3 4 9 1 4 /subsection1/foo NO 0
4 5 11 1 5 /subsection2/baz NO 0
5 6 13 1 6 /subsection2/foo NO 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ properties
3 4 items:1 1,2,3,4,5,6
4 5 ts:1:test:count 6
5 6 usn:1:test 19
6 7 ts:1:test 60b8a1a8cefc427df50f7860fa9a5d14
6 7 ts:1:test 6cc811fa3eeacbbfe8b8ac34d9e4d6f4
7 8 target:1:test_job:test d6300d865d6b3ead5d0fff503c5da8f6
8 9 target:mtime:1:test_job:test 12345678
9 10 source:1:test_job:test 9cc74248d8061fa6f550c68594c2abbf
10 11 source:ts:1:test_job:test
60b8a1a8cefc427df50f7860fa9a5d14
6cc811fa3eeacbbfe8b8ac34d9e4d6f4
11 12 job-hash:test_namespace:test_job
e247f4a31e8be51d175137608ffd4f5a
12 13 job-plugin:test_namespace:test_job parse_yaml.
Expand Down
12 changes: 6 additions & 6 deletions t/data/engine/parse_yaml/01/reference-output/database/strings
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
strings
{
0 1 2 etc2 NO 0
1 2 4 bar2 NO 0
2 3 6 etc1 NO 0
3 4 8 etc1 /subsection2/baz 0
4 5 10 bar1 NO 0
5 6 12 bar1 /foo 0
0 1 2 etc1 NO 0
1 2 4 bar1 NO 0
2 3 6 etc2 NO 0
3 4 8 bar2 NO 0
4 5 10 etc1 /subsection2/baz 0
5 6 12 bar1 /subsection2/foo 0
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
translations
{
0 1 14 1 test ēţç2 NO 0 0
1 2 15 2 test ḃáŕ2 NO 0 0
2 3 16 3 test ēţç1 NO 0 0
3 4 17 4 test ēţç1 NO 0 0
4 5 18 5 test ḃáŕ1 NO 0 0
0 1 14 1 test ēţç1 NO 0 0
1 2 15 2 test ḃáŕ1 NO 0 0
2 3 16 3 test ēţç2 NO 0 0
3 4 17 4 test ḃáŕ2 NO 0 0
4 5 18 5 test ēţç1 NO 0 0
5 6 19 6 test ḃáŕ1 NO 0 0
}
28 changes: 14 additions & 14 deletions t/data/engine/parse_yaml/01/reference-output/po/test/strings.yml.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ msgstr ""
"Language: test\n"
"Generated-By: Serge 1.1\n"

#. /baz
#: File: strings.yml
#: ID: 641460c2a4284dfe0a6e9b1368f89fd5
msgid "etc1"
msgstr "ēţç1"

#. /foo
#: File: strings.yml
#: ID: 2b2b5146df00a72b24a62de7f60c818b
msgid "bar1"
msgstr "ḃáŕ1"

#. /subsection1/baz
#: File: strings.yml
#: ID: d153669b002fd5ab4e43d885eb02f39c
Expand All @@ -17,12 +29,6 @@ msgstr "ēţç2"
msgid "bar2"
msgstr "ḃáŕ2"

#. /baz
#: File: strings.yml
#: ID: 641460c2a4284dfe0a6e9b1368f89fd5
msgid "etc1"
msgstr "ēţç1"

#. /subsection2/baz
#: File: strings.yml
#: ID: e3a130f8737c5bdb7197ca83dd2d04ae
Expand All @@ -32,13 +38,7 @@ msgstr "ēţç1"

#. /subsection2/foo
#: File: strings.yml
#: ID: 2b2b5146df00a72b24a62de7f60c818b
msgid "bar1"
msgstr "ḃáŕ1"

#. /foo
#: File: strings.yml
#: ID: ed5b712a73e268cee657f4082b990fc5
msgctxt "/foo"
#: ID: 1606cda5e41e69c2b1c7ea2ba261ba0c
msgctxt "/subsection2/foo"
msgid "bar1"
msgstr "ḃáŕ1"
6 changes: 3 additions & 3 deletions t/data/engine/parse_yaml/02/reference-output/database/items
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
items
{
0 1 3 1 1 /messages/baz NO 0
1 2 5 1 2 /messages/subsection/baz NO 0
2 3 7 1 3 /messages/subsection/foo NO 0
3 4 9 1 4 /messages/foo NO 0
1 2 5 1 2 /messages/foo NO 0
2 3 7 1 3 /messages/subsection/baz NO 0
3 4 9 1 4 /messages/subsection/foo NO 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ properties
3 4 items:1 1,2,3,4
4 5 ts:1:test:count 4
5 6 usn:1:test 13
6 7 ts:1:test d1f18a868b46fbd6f6bbc59f0a61a6b6
6 7 ts:1:test 3b010fe0f7df938839b514e71b4cea7e
7 8 target:1:test_job:test a34ea2a7ab5b90067203f0ea6313247f
8 9 target:mtime:1:test_job:test 12345678
9 10 source:1:test_job:test 9931e2731aec2b1d56f564b338cd1c59
10 11 source:ts:1:test_job:test
d1f18a868b46fbd6f6bbc59f0a61a6b6
3b010fe0f7df938839b514e71b4cea7e
11 12 job-hash:test_namespace:test_job
c2ddeb78ca623ddd463b7595aa56a916
12 13 job-plugin:test_namespace:test_job parse_yaml.
Expand Down
6 changes: 3 additions & 3 deletions t/data/engine/parse_yaml/02/reference-output/database/strings
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
strings
{
0 1 2 etc1 NO 0
1 2 4 etc2 NO 0
2 3 6 bar2 NO 0
3 4 8 bar1 NO 0
1 2 4 bar1 NO 0
2 3 6 etc2 NO 0
3 4 8 bar2 NO 0
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
translations
{
0 1 10 1 test ēţç1 NO 0 0
1 2 11 2 test ēţç2 NO 0 0
2 3 12 3 test ḃáŕ2 NO 0 0
3 4 13 4 test ḃáŕ1 NO 0 0
1 2 11 2 test ḃáŕ1 NO 0 0
2 3 12 3 test ēţç2 NO 0 0
3 4 13 4 test ḃáŕ2 NO 0 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ msgstr ""
msgid "etc1"
msgstr "ēţç1"

#. /messages/foo
#: File: strings.yml
#: ID: 2b2b5146df00a72b24a62de7f60c818b
msgid "bar1"
msgstr "ḃáŕ1"

#. /messages/subsection/baz
#: File: strings.yml
#: ID: d153669b002fd5ab4e43d885eb02f39c
Expand All @@ -22,9 +28,3 @@ msgstr "ēţç2"
#: ID: e5f2adbdbe00c558062db891f2072489
msgid "bar2"
msgstr "ḃáŕ2"

#. /messages/foo
#: File: strings.yml
#: ID: 2b2b5146df00a72b24a62de7f60c818b
msgid "bar1"
msgstr "ḃáŕ1"

0 comments on commit a6c4d3f

Please sign in to comment.