Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
c350e883
Unverified
Commit
c350e883
authored
Jun 13, 2022
by
Cristian Maglie
Committed by
GitHub
Jun 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[skip-changelog] Fixed LibraryLocation and LibraryLayout JSON encoder/decoders (#1757)
parent
899dc91b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
29 deletions
+75
-29
arduino/libraries/libraries_layout.go
arduino/libraries/libraries_layout.go
+10
-11
arduino/libraries/libraries_location.go
arduino/libraries/libraries_location.go
+15
-18
arduino/libraries/libraries_test.go
arduino/libraries/libraries_test.go
+50
-0
No files found.
arduino/libraries/libraries_layout.go
View file @
c350e883
...
...
@@ -38,19 +38,14 @@ func (d *LibraryLayout) String() string {
return
"flat"
case
RecursiveLayout
:
return
"recursive"
default
:
panic
(
fmt
.
Sprintf
(
"invalid LibraryLayout value %d"
,
*
d
))
}
panic
(
fmt
.
Sprintf
(
"invalid LibraryLayout value %d"
,
*
d
))
}
// MarshalJSON implements the json.Marshaler interface
func
(
d
*
LibraryLayout
)
MarshalJSON
()
([]
byte
,
error
)
{
switch
*
d
{
case
FlatLayout
:
return
json
.
Marshal
(
"flat"
)
case
RecursiveLayout
:
return
json
.
Marshal
(
"recursive"
)
}
return
nil
,
fmt
.
Errorf
(
tr
(
"invalid library layout value: %d"
),
*
d
)
func
(
d
LibraryLayout
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
d
.
String
())
}
// UnmarshalJSON implements the json.Unmarshaler interface
...
...
@@ -62,10 +57,13 @@ func (d *LibraryLayout) UnmarshalJSON(b []byte) error {
switch
s
{
case
"flat"
:
*
d
=
FlatLayout
return
nil
case
"recursive"
:
*
d
=
RecursiveLayout
return
nil
default
:
return
fmt
.
Errorf
(
tr
(
"invalid library layout: %s"
),
s
)
}
return
fmt
.
Errorf
(
tr
(
"invalid library layout: %s"
),
s
)
}
// ToRPCLibraryLayout converts this LibraryLayout to rpc.LibraryLayout
...
...
@@ -75,6 +73,7 @@ func (d *LibraryLayout) ToRPCLibraryLayout() rpc.LibraryLayout {
return
rpc
.
LibraryLayout_LIBRARY_LAYOUT_FLAT
case
RecursiveLayout
:
return
rpc
.
LibraryLayout_LIBRARY_LAYOUT_RECURSIVE
default
:
panic
(
fmt
.
Sprintf
(
"invalid LibraryLayout value %d"
,
*
d
))
}
panic
(
fmt
.
Sprintf
(
"invalid LibraryLayout value %d"
,
*
d
))
}
arduino/libraries/libraries_location.go
View file @
c350e883
...
...
@@ -52,25 +52,14 @@ func (d *LibraryLocation) String() string {
return
"user"
case
Unmanaged
:
return
"unmanaged"
default
:
panic
(
fmt
.
Sprintf
(
"invalid LibraryLocation value %d"
,
*
d
))
}
panic
(
fmt
.
Sprintf
(
"invalid LibraryLocation value %d"
,
*
d
))
}
// MarshalJSON implements the json.Marshaler interface
func
(
d
*
LibraryLocation
)
MarshalJSON
()
([]
byte
,
error
)
{
switch
*
d
{
case
IDEBuiltIn
:
return
json
.
Marshal
(
"ide"
)
case
PlatformBuiltIn
:
return
json
.
Marshal
(
"platform"
)
case
ReferencedPlatformBuiltIn
:
return
json
.
Marshal
(
"ref-platform"
)
case
User
:
return
json
.
Marshal
(
"user"
)
case
Unmanaged
:
return
json
.
Marshal
(
"unmanaged"
)
}
return
nil
,
fmt
.
Errorf
(
tr
(
"invalid library location value: %d"
),
*
d
)
func
(
d
LibraryLocation
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
d
.
String
())
}
// UnmarshalJSON implements the json.Unmarshaler interface
...
...
@@ -82,16 +71,22 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error {
switch
s
{
case
"ide"
:
*
d
=
IDEBuiltIn
return
nil
case
"platform"
:
*
d
=
PlatformBuiltIn
return
nil
case
"ref-platform"
:
*
d
=
ReferencedPlatformBuiltIn
return
nil
case
"user"
:
*
d
=
User
return
nil
case
"unmanaged"
:
*
d
=
Unmanaged
return
nil
default
:
return
fmt
.
Errorf
(
tr
(
"invalid library location: %s"
),
s
)
}
return
fmt
.
Errorf
(
tr
(
"invalid library location: %s"
),
s
)
}
// ToRPCLibraryLocation converts this LibraryLocation to rpc.LibraryLocation
...
...
@@ -107,8 +102,9 @@ func (d *LibraryLocation) ToRPCLibraryLocation() rpc.LibraryLocation {
return
rpc
.
LibraryLocation_LIBRARY_LOCATION_USER
case
Unmanaged
:
return
rpc
.
LibraryLocation_LIBRARY_LOCATION_UNMANAGED
default
:
panic
(
fmt
.
Sprintf
(
"invalid LibraryLocation value %d"
,
*
d
))
}
panic
(
fmt
.
Sprintf
(
"invalid LibraryLocation value %d"
,
*
d
))
}
// FromRPCLibraryLocation converts a rpc.LibraryLocation to a LibraryLocation
...
...
@@ -124,6 +120,7 @@ func FromRPCLibraryLocation(l rpc.LibraryLocation) LibraryLocation {
return
User
case
rpc
.
LibraryLocation_LIBRARY_LOCATION_UNMANAGED
:
return
Unmanaged
default
:
panic
(
fmt
.
Sprintf
(
"invalid rpc.LibraryLocation value %d"
,
l
))
}
panic
(
fmt
.
Sprintf
(
"invalid rpc.LibraryLocation value %d"
,
l
))
}
arduino/libraries/libraries_test.go
0 → 100644
View file @
c350e883
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.
package
libraries
import
(
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
)
func
TestLibLayoutAndLocationJSONUnMarshaler
(
t
*
testing
.
T
)
{
testLayout
:=
func
(
l
LibraryLayout
)
{
d
,
err
:=
json
.
Marshal
(
l
)
require
.
NoError
(
t
,
err
)
var
m
LibraryLayout
err
=
json
.
Unmarshal
(
d
,
&
m
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
l
,
m
)
}
testLayout
(
FlatLayout
)
testLayout
(
RecursiveLayout
)
testLocation
:=
func
(
l
LibraryLocation
)
{
d
,
err
:=
json
.
Marshal
(
l
)
require
.
NoError
(
t
,
err
)
var
m
LibraryLocation
err
=
json
.
Unmarshal
(
d
,
&
m
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
l
,
m
)
}
testLocation
(
IDEBuiltIn
)
testLocation
(
PlatformBuiltIn
)
testLocation
(
ReferencedPlatformBuiltIn
)
testLocation
(
User
)
testLocation
(
Unmanaged
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment