Skip to content

Commit

Permalink
XBRL Unmarshalling (#6)
Browse files Browse the repository at this point in the history
* proper xml unmarshalling support and validation

* add test for old xbrl
  • Loading branch information
mmoghaddam385 authored Jun 8, 2021
1 parent 5196bb4 commit d412d69
Show file tree
Hide file tree
Showing 8 changed files with 9,004 additions and 12 deletions.
16 changes: 8 additions & 8 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ type PeriodType string

// All the supported PeriodType values. See Period.Type() for more information.
const (
Duration PeriodType = "duration"
Instant PeriodType = "instant"
Forever PeriodType = "forever"
Invalid PeriodType = "invalid"
PeriodTypeDuration PeriodType = "duration"
PeriodTypeInstant PeriodType = "instant"
PeriodTypeForever PeriodType = "forever"
PeriodTypeInvalid PeriodType = "invalid"
)

// Period contains an instant or interval of time for a Context.
Expand All @@ -91,16 +91,16 @@ type Period struct {
// The comments on the attributes inside the Period struct explain when they can be used depending on what this function returns.
func (p Period) Type() PeriodType {
if p.Forever != nil {
return Forever
return PeriodTypeForever
}

if p.Instant != nil {
return Instant
return PeriodTypeInstant
}

if p.StartDate != nil && p.EndDate != nil {
return Duration
return PeriodTypeDuration
}

return Invalid
return PeriodTypeInvalid
}
6 changes: 3 additions & 3 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestUnmarshalContext(t *testing.T) {

assert.Equal(t, "http://www.sec.gov/CIK", context.Entity.Identifier.Scheme)
assert.Equal(t, "0000320193", context.Entity.Identifier.Value)
assert.Equal(t, Instant, context.Period.Type())
assert.Equal(t, PeriodTypeInstant, context.Period.Type())
assert.Equal(t, "2021-04-16", *context.Period.Instant)
})

Expand All @@ -45,7 +45,7 @@ func TestUnmarshalContext(t *testing.T) {

assert.Equal(t, "http://www.sec.gov/CIK", context.Entity.Identifier.Scheme)
assert.Equal(t, "0000320193", context.Entity.Identifier.Value)
assert.Equal(t, Forever, context.Period.Type())
assert.Equal(t, PeriodTypeForever, context.Period.Type())
})

t.Run("duration period | has segments", func(t *testing.T) {
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestUnmarshalContext(t *testing.T) {
assert.Empty(t, context.Entity.Segments[1].Attributes)
assert.Equal(t, "I follow my own rules", context.Entity.Segments[1].Value)

assert.Equal(t, Duration, context.Period.Type())
assert.Equal(t, PeriodTypeDuration, context.Period.Type())
assert.Equal(t, "2020-09-27", *context.Period.StartDate)
assert.Equal(t, "2021-03-27", *context.Period.EndDate)
})
Expand Down
Loading

0 comments on commit d412d69

Please sign in to comment.