A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/arduino/arduino-lint/commit/3b6da1c3882249d5f48be3ef7849d86939d8d7ff below:

Merge pull request #266 from per1234/fix-overlapping-prop-mapping · arduino/arduino-lint@3b6da1c · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+37

-12

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+37

-12

lines changed Original file line number Diff line number Diff line change

@@ -32,20 +32,19 @@ In the event a full recursion of key levels is desired, set the levels argument

32 32

func PropertiesToMap(flatProperties *properties.Map, levels int) map[string]interface{} {

33 33

propertiesInterface := make(map[string]interface{})

34 34 35 -

var keys []string

36 35

if levels != 1 {

37 -

keys = flatProperties.FirstLevelKeys()

36 +

for _, key := range flatProperties.FirstLevelKeys() {

37 +

subTree := flatProperties.SubTree(key)

38 +

if subTree.Size() > 0 {

39 +

// This key contains a map.

40 +

propertiesInterface[key] = PropertiesToMap(subTree, levels-1)

41 +

} else {

42 +

// This key contains a string, no more recursion is possible.

43 +

propertiesInterface[key] = flatProperties.Get(key)

44 +

}

45 +

}

38 46

} else {

39 -

keys = flatProperties.Keys()

40 -

}

41 - 42 -

for _, key := range keys {

43 -

subTree := flatProperties.SubTree(key)

44 -

if subTree.Size() > 0 {

45 -

// This key contains a map.

46 -

propertiesInterface[key] = PropertiesToMap(subTree, levels-1)

47 -

} else {

48 -

// This key contains a string, no more recursion is possible.

47 +

for _, key := range flatProperties.Keys() {

49 48

propertiesInterface[key] = flatProperties.Get(key)

50 49

}

51 50

}

Original file line number Diff line number Diff line change

@@ -31,6 +31,10 @@ func TestPropertiesToMap(t *testing.T) {

31 31

foo.bar=asdf

32 32

foo.baz=zxcv

33 33

bar.bat.bam=123

34 +

qux.a=x

35 +

qux.a.b=y

36 +

fuz.a.b=y

37 +

fuz.a=x

34 38

`)

35 39

propertiesInput, err := properties.LoadFromBytes(rawProperties)

36 40

require.Nil(t, err)

@@ -41,6 +45,10 @@ func TestPropertiesToMap(t *testing.T) {

41 45

"foo.bar": "asdf",

42 46

"foo.baz": "zxcv",

43 47

"bar.bat.bam": "123",

48 +

"qux.a": "x",

49 +

"qux.a.b": "y",

50 +

"fuz.a.b": "y",

51 +

"fuz.a": "x",

44 52

}

45 53 46 54

assert.True(t, reflect.DeepEqual(expectedMapOutput, PropertiesToMap(propertiesInput, 1)))

@@ -55,6 +63,14 @@ func TestPropertiesToMap(t *testing.T) {

55 63

"bar": map[string]interface{}{

56 64

"bat.bam": "123",

57 65

},

66 +

"qux": map[string]interface{}{

67 +

"a": "x",

68 +

"a.b": "y",

69 +

},

70 +

"fuz": map[string]interface{}{

71 +

"a.b": "y",

72 +

"a": "x",

73 +

},

58 74

}

59 75 60 76

assert.True(t, reflect.DeepEqual(expectedMapOutput, PropertiesToMap(propertiesInput, 2)))

@@ -71,6 +87,16 @@ func TestPropertiesToMap(t *testing.T) {

71 87

"bam": "123",

72 88

},

73 89

},

90 +

"qux": map[string]interface{}{

91 +

"a": map[string]interface{}{

92 +

"b": "y", // It is impossible to represent the complete "properties" data structure recursed to this depth.

93 +

},

94 +

},

95 +

"fuz": map[string]interface{}{

96 +

"a": map[string]interface{}{

97 +

"b": "y",

98 +

},

99 +

},

74 100

}

75 101 76 102

assert.True(t, reflect.DeepEqual(expectedMapOutput, PropertiesToMap(propertiesInput, 3)))

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4