Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Fix unit test fn name, add HR check support
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseCoretta committed Jul 31, 2024
1 parent 262500a commit 9c9426d
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 62 deletions.
2 changes: 1 addition & 1 deletion at_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ In essence, this method is the opposite of the [AttributeType.SuperType]
method and may return zero (0) or more [AttributeType] instances within
the return [AttributeTypes] instance.
*/
func ExampleAttribute_SubTypes() {
func ExampleAttributeType_SubTypes() {
def := mySchema.AttributeTypes().Get(`name`)
fmt.Printf("%d subordinate types found", def.SubTypes().Len())
// Output: 15 subordinate types found
Expand Down
66 changes: 33 additions & 33 deletions ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func (r Schema) DITStructureRules() (dss DITStructureRules) {
return
}

func (r DITStructureRule) schema() (s Schema) {
if !r.IsZero() {
s = r.dITStructureRule.schema
}
return
}
func (r DITStructureRule) schema() (s Schema) {
if !r.IsZero() {
s = r.dITStructureRule.schema
}

return
}

/*
Replace overrides the receiver with x. Both must bear an identical
Expand Down Expand Up @@ -273,33 +273,33 @@ func (r DITStructureRule) SuperRules() (sup DITStructureRules) {
return
}

/*
SubRules returns an instance of [DITStructureRules] containing slices of
[DITStructureRule] instances that are direct subordinates to the receiver
instance. As such, this method is essentially the inverse of the
[DITStructureRule.SuperRules] method.
/*
SubRules returns an instance of [DITStructureRules] containing slices of
[DITStructureRule] instances that are direct subordinates to the receiver
instance. As such, this method is essentially the inverse of the
[DITStructureRule.SuperRules] method.
The super chain is NOT traversed beyond immediate subordinate instances.
Note that the relevant [Schema] instance must have been set using the
[DITStructureRule.SetSchema] method prior to invocation of this method.
Should this requirement remain unfulfilled, the return instance will
be a zero instance.
*/
func (r DITStructureRule) SubRules() (subs DITStructureRules) {
if !r.IsZero() {
subs = NewDITStructureRuleIDList()
dsrs := r.schema().DITStructureRules()
for i := 0; i < dsrs.Len(); i++ {
typ := dsrs.Index(i)
supers := typ.SuperRules()
if got := supers.Get(r.RuleID()); !got.IsZero() {
subs.Push(typ)
}
}
}
return
Note that the relevant [Schema] instance must have been set using the
[DITStructureRule.SetSchema] method prior to invocation of this method.
Should this requirement remain unfulfilled, the return instance will
be a zero instance.
*/
func (r DITStructureRule) SubRules() (subs DITStructureRules) {
if !r.IsZero() {
subs = NewDITStructureRuleIDList()
dsrs := r.schema().DITStructureRules()
for i := 0; i < dsrs.Len(); i++ {
typ := dsrs.Index(i)
supers := typ.SuperRules()
if got := supers.Get(r.RuleID()); !got.IsZero() {
subs.Push(typ)
}
}
}

return
}

/*
Expand Down
6 changes: 3 additions & 3 deletions ds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ method and may return zero (0) or more [DITStructureRule] instances within
the return [DITStructureRules] instance.
*/
func ExampleDITStructureRule_SubRules() {
def := mySchema.DITStructureRules().Get(0)
fmt.Printf("%d subordinate rules found", def.SubRules().Len())
// Output: 2 subordinate rules found
def := mySchema.DITStructureRules().Get(0)
fmt.Printf("%d subordinate rules found", def.SubRules().Len())
// Output: 2 subordinate rules found
}

/*
Expand Down
4 changes: 2 additions & 2 deletions imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/JesseCoretta/go-schemax/internal/rfc2079"
"github.com/JesseCoretta/go-schemax/internal/rfc2307"
"github.com/JesseCoretta/go-schemax/internal/rfc2589"
"github.com/JesseCoretta/go-schemax/internal/rfc2798"
"github.com/JesseCoretta/go-schemax/internal/rfc2798"
"github.com/JesseCoretta/go-schemax/internal/rfc3045"
"github.com/JesseCoretta/go-schemax/internal/rfc3671"
"github.com/JesseCoretta/go-schemax/internal/rfc3672"
Expand All @@ -20,7 +20,7 @@ import (
"github.com/JesseCoretta/go-schemax/internal/rfc4524"
"github.com/JesseCoretta/go-schemax/internal/rfc4530"
"github.com/JesseCoretta/go-schemax/internal/rfc5020"
"github.com/JesseCoretta/go-schemax/internal/x501"
"github.com/JesseCoretta/go-schemax/internal/x501"

"github.com/JesseCoretta/go-objectid"
"github.com/JesseCoretta/go-shifty"
Expand Down
27 changes: 27 additions & 0 deletions ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ func (r *lDAPSyntax) setStringer(function ...Stringer) {
}

/*
NOT YET IMPLEMENTED
xOrigin returns an instance of LDAPSyntaxes containing only definitions
which bear the X-ORIGIN value of x. Case is not significant in the matching
process, nor is whitespace (e.g.: RFC 4517 vs. RFC4517).
Expand All @@ -258,6 +260,31 @@ func (r LDAPSyntaxes) xOrigin(x string) (lss LDAPSyntaxes) {
}
*/

/*
HumanReadable returns a Boolean value indicative of whether the receiver
is considered a HUMAN-READABLE (HR) syntax.
To that end, the determination is made based on the presence of the
'X-NOT-HUMAN-READABLE' [Extension] bearing a value of 'TRUE'. In this
state, a value of false is returned, indicating the [LDAPSyntax] is NOT
considered HUMAN-READABLE. A value of false is also returned if the
receiver is nil.
All other states return true.
*/
func (r LDAPSyntax) HumanReadable() bool {
if r.IsZero() {
return false
}

ext, _ := r.Extensions().Get(`X-NOT-HUMAN-READABLE`)
if ext.IsZero() {
return true
}

return !ext.Contains(`TRUE`) // invert evaluation
}

/*
String is a stringer method that returns the string representation
of the receiver instance.
Expand Down
12 changes: 12 additions & 0 deletions ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ func ExampleLDAPSyntax_NumericOID() {
// Output: 1.3.6.1.4.1.1466.115.121.1.27
}

/*
This example demonstrates a simple means of determining whether the
receiver instance describes a human-readable [LDAPSyntax].
*/
func ExampleLDAPSyntax_HumanReadable() {
def := mySchema.LDAPSyntaxes().Get(`1.3.6.1.1.15.7`)
fmt.Printf("%s is human-readable: %t", def.Description(), def.HumanReadable())
// Output: X.509 Algorithm Identifier is human-readable: false
}

/*
This example demonstrates the means for accessing the description OR
numeric OID of the receiver instance.
Expand Down Expand Up @@ -318,6 +328,7 @@ func TestLDAPSyntax_codecov(t *testing.T) {
_ = def.String()
_ = def.SetStringer()
_ = def.Description()
_ = def.HumanReadable()
_ = def.Name()
_ = def.Names()
_ = def.Extensions()
Expand Down Expand Up @@ -363,6 +374,7 @@ func TestLDAPSyntax_codecov(t *testing.T) {
}
_ = def.macro()
def.setOID(`1.3.6.1.4.1.56521.999.88.5`)
_ = def.HumanReadable()

var def2 LDAPSyntax
_ = def2.Replace(def) // will fail
Expand Down
30 changes: 15 additions & 15 deletions oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,28 +655,28 @@ Should this requirement remain unfulfilled, the return instance will
be a zero instance.
*/
func (r ObjectClass) SubClasses() (subs ObjectClasses) {
if !r.IsZero() {
subs = NewObjectClassOIDList()
ocs := r.schema().ObjectClasses()
for i := 0; i < ocs.Len(); i++ {
typ := ocs.Index(i)
if !r.IsZero() {
subs = NewObjectClassOIDList()
ocs := r.schema().ObjectClasses()
for i := 0; i < ocs.Len(); i++ {
typ := ocs.Index(i)
supers := typ.SuperClasses()
if got := supers.Get(r.NumericOID()); !got.IsZero() {
subs.Push(typ)
}
}
}
}
}

return
return
}

func (r ObjectClass) schema() (s Schema) {
if !r.IsZero() {
s = r.objectClass.schema
}
return
}
func (r ObjectClass) schema() (s Schema) {
if !r.IsZero() {
s = r.objectClass.schema
}

return
}

/*
SuperChain returns an [ObjectClasses] stack of [ObjectClass] instances
Expand Down
16 changes: 8 additions & 8 deletions oc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ func ExampleObjectClass_SuperClassOf() {
// Output: true
}

/*
/*
This example demonstrates the means of accessing all subordinate class
instances of the receiver instance.
instances of the receiver instance.
In essence, this method is the opposite of the [ObjectClass.SuperClasses]
method and may return zero (0) or more [ObjectClasses] instances within
the return [ObjectClasses] instance.
method and may return zero (0) or more [ObjectClasses] instances within
the return [ObjectClasses] instance.
*/
func ExampleObjectClass_SubClasses() {
def := mySchema.ObjectClasses().Get(`top`)
fmt.Printf("%d subordinate classes found", def.SubClasses().Len())
// Output: 49 subordinate classes found
def := mySchema.ObjectClasses().Get(`top`)
fmt.Printf("%d subordinate classes found", def.SubClasses().Len())
// Output: 49 subordinate classes found
}

/*
Expand Down

0 comments on commit 9c9426d

Please sign in to comment.