Repository navigation
fix(record): keep mixed-unit sequences as text and refuse repeats into a unique member #610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
ac360e7
fix(record): preserve sequence compatibility with existing definitions
devin-ai-integration[bot] 2866f31
docs(record): document the repeated-literal check and its changelog f…
devin-ai-integration[bot] 6063860
fix(record): judge repeated sequence elements by value, across runs
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - **A sequence mixing a quantity with a plain number records as text.** It has no single unit to record under, so it no longer settles to a bare Real that drops the measured element's unit. | ||
| - **A repeated sequence value is refused by an existing unique record member.** Recording into a definition that declares the member `[0..*]` without `nonunique` names the `into` remedy instead of generating a record that fails validation; generated definitions, declared `ordered nonunique`, keep admitting repeats. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package record | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/Open-MBEE/OpenSysML/internal/exec/runtime" | ||
| "github.com/Open-MBEE/OpenSysML/internal/syntax/format" | ||
| ) | ||
|
|
||
| func TestGenerateSequenceMixedQuantityAndNumberFallsBackToText(t *testing.T) { | ||
| res, err := Generate(Request{ | ||
| Package: "Records", Case: "P::temps", Provenance: provenance(KindRun), | ||
| Runs: []Run{{ | ||
| Spell: spell(), | ||
| Outputs: []runtime.CalcOutputValue{{Name: "temps", Value: seqOf(kelvin(300), integer(301))}}, | ||
| }}, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Generate: %v", err) | ||
| } | ||
| for _, want := range []string{ | ||
| "attribute temps : ScalarValues::String;", | ||
| `attribute :>> temps = "[300.0 [K], 301]";`, | ||
| } { | ||
| if !strings.Contains(res.Source, want) { | ||
| t.Errorf("source is missing %q:\n%s", want, res.Source) | ||
| } | ||
| } | ||
| if strings.Contains(res.Source, "tempsUnit") { | ||
| t.Errorf("mixed quantity/plain sequence unexpectedly has a unit companion:\n%s", res.Source) | ||
| } | ||
| } | ||
|
|
||
| func TestGenerateExistingSequenceRejectsRepeatedValuesForUniqueMember(t *testing.T) { | ||
| _, err := Generate(Request{ | ||
| Package: "Records", Case: "P::temps", Provenance: provenance(KindRun), | ||
| Runs: []Run{{Spell: spell(), Outputs: []runtime.CalcOutputValue{{Name: "temps", Value: seqOf(realValue(300), realValue(300), realValue(341.2))}}}}, | ||
| Existing: Existing{Definition: true, Stem: "temps", Attributes: map[string]Feature{ | ||
| "temps": {TypeFQN: scalarValuesReal, Multi: true, Unique: true}, | ||
| }}, | ||
| }) | ||
| if err == nil || !strings.Contains(err.Error(), "declares temps unique but the run values repeat a value") { | ||
| t.Fatalf("Generate = %v, want the unique repeated-value refusal", err) | ||
| } | ||
| } | ||
|
|
||
| // Value equality, not literal spelling, detects a repeat: an Integer 1 and a | ||
| // Real 1.0 are one value to a unique member. | ||
| func TestGenerateExistingSequenceRejectsARepeatAcrossNumericKinds(t *testing.T) { | ||
| _, err := Generate(Request{ | ||
| Package: "Records", Case: "P::temps", Provenance: provenance(KindRun), | ||
| Runs: []Run{{Spell: spell(), Outputs: []runtime.CalcOutputValue{{Name: "temps", Value: seqOf(integer(1), realValue(1.0))}}}}, | ||
| Existing: Existing{Definition: true, Stem: "temps", Attributes: map[string]Feature{ | ||
| "temps": {TypeFQN: scalarValuesReal, Multi: true, Unique: true}, | ||
| }}, | ||
| }) | ||
| if err == nil || !strings.Contains(err.Error(), "declares temps unique but the run values repeat a value") { | ||
| t.Fatalf("Generate = %v, want the unique repeated-value refusal", err) | ||
| } | ||
| } | ||
|
|
||
| // A repeat in a later run marks the member even though the merge settles its | ||
| // shape over runs that did not repeat. | ||
| func TestGenerateExistingSequenceARepeatInALaterRun(t *testing.T) { | ||
| cases := map[string]struct { | ||
| unique bool | ||
| wantErr bool | ||
| }{ | ||
| "unique member refuses": {unique: true, wantErr: true}, | ||
| "nonunique member accepts": {unique: false}, | ||
| } | ||
| for name, tc := range cases { | ||
| t.Run(name, func(t *testing.T) { | ||
| res, err := Generate(Request{ | ||
| Package: "Records", Case: "P::temps", Provenance: provenance(KindRun), | ||
| Runs: []Run{ | ||
| {Spell: spell(), Outputs: []runtime.CalcOutputValue{{Name: "temps", Value: seqOf(realValue(300), realValue(310))}}}, | ||
| {Spell: spell(), Outputs: []runtime.CalcOutputValue{{Name: "temps", Value: seqOf(realValue(300), realValue(300))}}}, | ||
| }, | ||
| Existing: Existing{Definition: true, Stem: "temps", Attributes: map[string]Feature{ | ||
| "temps": {TypeFQN: scalarValuesReal, Multi: true, Unique: tc.unique}, | ||
| }}, | ||
| }) | ||
| if tc.wantErr { | ||
| if err == nil || !strings.Contains(err.Error(), "declares temps unique but the run values repeat a value") { | ||
| t.Fatalf("Generate = %v, want the unique repeated-value refusal", err) | ||
| } | ||
| return | ||
| } | ||
| if err != nil { | ||
| t.Fatalf("Generate: %v", err) | ||
| } | ||
| if _, err := format.Source("<record>", []byte(res.Source), format.DefaultOptions); err != nil { | ||
| t.Fatalf("generated source does not parse: %v", err) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGenerateExistingSequenceCompatibility(t *testing.T) { | ||
| cases := map[string]struct { | ||
| values []runtime.Value | ||
| unique bool | ||
| }{ | ||
| "unique values in unique member": {values: []runtime.Value{realValue(300), realValue(310)}, unique: true}, | ||
| "repeated values in nonunique member": {values: []runtime.Value{realValue(300), realValue(300)}, unique: false}, | ||
| } | ||
| for name, tc := range cases { | ||
| t.Run(name, func(t *testing.T) { | ||
| res, err := Generate(Request{ | ||
| Package: "Records", Case: "P::temps", Provenance: provenance(KindRun), | ||
| Runs: []Run{{Spell: spell(), Outputs: []runtime.CalcOutputValue{{Name: "temps", Value: seqOf(tc.values...)}}}}, | ||
| Existing: Existing{Definition: true, Stem: "temps", Attributes: map[string]Feature{ | ||
| "temps": {TypeFQN: scalarValuesReal, Multi: true, Unique: tc.unique}, | ||
| }}, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Generate: %v", err) | ||
| } | ||
| if _, err := format.Source("<record>", []byte(res.Source), format.DefaultOptions); err != nil { | ||
| t.Fatalf("generated source does not parse: %v", err) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package repl | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/Open-MBEE/OpenSysML/internal/semantic/resolve" | ||
| "github.com/Open-MBEE/OpenSysML/internal/semantic/semantics" | ||
| ) | ||
|
|
||
| func TestRecordAttributesReportsSequenceUniqueness(t *testing.T) { | ||
| for name, declaration := range map[string]string{ | ||
| "unique": "attribute temps : Real[0..*];", | ||
| "nonunique": "attribute temps : Real[0..*] nonunique;", | ||
| } { | ||
| t.Run(name, func(t *testing.T) { | ||
| s := NewSession() | ||
| model := `package Records { | ||
| private import ScalarValues::*; | ||
| private import AnalysisRecords::*; | ||
| part def Rec :> AnalysisRecords::AnalysisRun { ` + declaration + ` } | ||
| }` | ||
| if errs := errorDiagnostics(s.Submit(model).Diagnostics); len(errs) > 0 { | ||
| t.Fatalf("model has errors: %v", errs) | ||
| } | ||
| idx := s.symbolIndex() | ||
| defs := idx.LookupQualified("Records::Rec") | ||
| if len(defs) != 1 { | ||
| t.Fatalf("Records::Rec resolves to %d symbols", len(defs)) | ||
| } | ||
| resolver := resolve.New(idx) | ||
| sem := semantics.NewModel(resolver) | ||
| resolver.SetModel(sem) | ||
| feature, ok := recordAttributes(idx, sem, defs[0])["temps"] | ||
| if !ok || !feature.Multi { | ||
| t.Fatalf("temps = %+v (present %v), want a multi-valued feature", feature, ok) | ||
| } | ||
| wantUnique := name == "unique" | ||
| if feature.Unique != wantUnique { | ||
| t.Errorf("temps.Unique = %v, want %v", feature.Unique, wantUnique) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestRecordAttributesFollowsInheritedNonunique(t *testing.T) { | ||
| s := NewSession() | ||
| model := `package Records { | ||
| private import ScalarValues::*; | ||
| private import AnalysisRecords::*; | ||
| part def Base { attribute temps : Real[0..*] nonunique; } | ||
| part def Rec :> Base, AnalysisRecords::AnalysisRun { attribute :>> temps; } | ||
| }` | ||
| if errs := errorDiagnostics(s.Submit(model).Diagnostics); len(errs) > 0 { | ||
| t.Fatalf("model has errors: %v", errs) | ||
| } | ||
| idx := s.symbolIndex() | ||
| defs := idx.LookupQualified("Records::Rec") | ||
| if len(defs) != 1 { | ||
| t.Fatalf("Records::Rec resolves to %d symbols", len(defs)) | ||
| } | ||
| resolver := resolve.New(idx) | ||
| sem := semantics.NewModel(resolver) | ||
| resolver.SetModel(sem) | ||
| feature, ok := recordAttributes(idx, sem, defs[0])["temps"] | ||
| if !ok || !feature.Multi || feature.Unique { | ||
| t.Errorf("temps = %+v (present %v), want inherited multi nonunique feature", feature, ok) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.