Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cedar-policy/cedar-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.2.0
Choose a base ref
...
head repository: cedar-policy/cedar-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.3.0
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Sep 5, 2024

  1. cedar: change JSON marshaling of the Position struct to use conventio…

    …nal lower case keys
    
    Technically, this is a breaking change and will require us to go to 0.3.0.
    
    Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
    patjakdev committed Sep 5, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a94e3e2 View commit details
  2. Merge pull request #28 from strongdm/main

    cedar: change JSON marshaling of the Position struct to use conventional lower case keys
    patjakdev authored Sep 5, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    76c9352 View commit details
Showing with 29 additions and 4 deletions.
  1. +11 −4 policy.go
  2. +18 −0 policy_test.go
15 changes: 11 additions & 4 deletions policy.go
Original file line number Diff line number Diff line change
@@ -97,10 +97,17 @@ func (p *Policy) Effect() Effect {

// A Position describes an arbitrary source position including the file, line, and column location.
type Position struct {
Filename string // optional name of the source file for the enclosing policy, "" if the source is unknown or not a named file
Offset int // byte offset, starting at 0
Line int // line number, starting at 1
Column int // column number, starting at 1 (character count per line)
// Filename is the optional name of the source file for the enclosing policy, "" if the source is unknown or not a named file
Filename string `json:"filename"`

// Offset is the byte offset, starting at 0
Offset int `json:"offset"`

// Line is the line number, starting at 1
Line int `json:"line"`

// Column is the column number, starting at 1 (character count per line)
Column int `json:"column"`
}

// Position retrieves the position of this policy.
18 changes: 18 additions & 0 deletions policy_test.go
Original file line number Diff line number Diff line change
@@ -108,3 +108,21 @@ func TestUnmarshalCedarPolicyErr(t *testing.T) {
err := p.UnmarshalCedar([]byte("!@#$"))
testutil.Error(t, err)
}

func TestPositionJSON(t *testing.T) {
t.Parallel()
p := cedar.Position{Filename: "foo.cedar", Offset: 1, Line: 2, Column: 3}

marshaled, err := json.MarshalIndent(p, "", "\t")
testutil.OK(t, err)

var want bytes.Buffer
_ = json.Indent(&want, []byte(`{ "filename": "foo.cedar", "offset": 1, "line": 2, "column": 3 }`), "", "\t")

testutil.Equals(t, string(marshaled), want.String())

var unmarshaled cedar.Position
testutil.OK(t, json.Unmarshal(want.Bytes(), &unmarshaled))

testutil.Equals(t, unmarshaled, p)
}