Skip to content

Commit

Permalink
Merge 68c7e83 into 75d964c
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Dec 19, 2023
2 parents 75d964c + 68c7e83 commit 3239ba3
Show file tree
Hide file tree
Showing 87 changed files with 486 additions and 428 deletions.
21 changes: 17 additions & 4 deletions cmd/enumerator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
//
// func ParseT(string) (T, error)
// func (t T) String() string
// func (t T) MarshalText() ([]byte, error)
//
// and for each value X
//
Expand All @@ -60,11 +61,12 @@
//
// enumerator -type=Pill
//
// in the same directory will create the file pill_string.go, in package painkiller,
// in the same directory will create the file enum_pill.go, in package painkiller,
// containing definitions of
//
// func ParsePill() (Pill, error)
// func (Pill) String() string
// func (Pill) MarshalText() ([]byte, error)
// func (Pill) IsPlacebo() bool
// func (Pill) IsAspirin() bool
// func (Pill) IsIbuprofen() bool
Expand Down Expand Up @@ -97,9 +99,9 @@
//
// PillAspirin
//
// a IsAspirin() method would still be generated, painkiller.Aspirin.String()
// would return "Aspirin" and ParsePill("Aspirin") would return
// painkiller.Aspirin.
// an IsAspirin() method would still be generated,
// painkiller.PillAspirin.String() would return "Aspirin" and
// ParsePill("Aspirin") would return painkiller.PillAspirin.
//
// The -empty flag tells enumerator to generate a method to check whether the
// underlying value is 0. This is useful when an enum is defined using iota+1.
Expand Down Expand Up @@ -309,6 +311,7 @@ func (g *Generator) generate(typeName string) {
g.buildMap(runs, typeName)
}

g.buildMarshalTextMethod(typeName)
g.buildIsMethods(runs, typeName)
g.buildParseMethod(runs, typeName)
g.buildValues(runs, typeName)
Expand Down Expand Up @@ -572,6 +575,16 @@ func (g *Generator) createIndexAndNameDecl(run []Value, typeName string, suffix
return b.String(), nameConst
}

func (g *Generator) buildMarshalTextMethod(typeName string) {
g.Printf(marshalTextMethod, typeName)
}

const marshalTextMethod = `
func (i %[1]s) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
`

func (g *Generator) buildIsMethods(runs [][]Value, typeName string) {
for _, values := range runs {
for _, value := range values {
Expand Down
36 changes: 36 additions & 0 deletions cmd/enumerator/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func (i Day) String() string {
return _Day_name[_Day_index[i]:_Day_index[i+1]]
}
func (i Day) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
func (i Day) IsMonday() bool {
return i == Monday
}
Expand Down Expand Up @@ -187,6 +191,10 @@ func (i Number) String() string {
return _Number_name[_Number_index[i]:_Number_index[i+1]]
}
func (i Number) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
func (i Number) IsOne() bool {
return i == One
}
Expand Down Expand Up @@ -279,6 +287,10 @@ func (i Gap) String() string {
}
}
func (i Gap) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
func (i Gap) IsTwo() bool {
return i == Two
}
Expand Down Expand Up @@ -391,6 +403,10 @@ func (i Num) String() string {
return _Num_name[_Num_index[i]:_Num_index[i+1]]
}
func (i Num) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
func (i Num) Ism_2() bool {
return i == m_2
}
Expand Down Expand Up @@ -492,6 +508,10 @@ func (i Unum) String() string {
}
}
func (i Unum) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
func (i Unum) Ism0() bool {
return i == m0
}
Expand Down Expand Up @@ -594,6 +614,10 @@ func (i Unumpos) String() string {
}
}
func (i Unumpos) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
func (i Unumpos) Ism1() bool {
return i == m1
}
Expand Down Expand Up @@ -714,6 +738,10 @@ func (i Prime) String() string {
return "Prime(" + strconv.FormatInt(int64(i), 10) + ")"
}
func (i Prime) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
func (i Prime) Isp2() bool {
return i == p2
}
Expand Down Expand Up @@ -868,6 +896,10 @@ func (i Type) String() string {
return _Type_name[_Type_index[i]:_Type_index[i+1]]
}
func (i Type) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
func (i Type) IsInt() bool {
return i == TypeInt
}
Expand Down Expand Up @@ -981,6 +1013,10 @@ func (i Token) String() string {
return _Token_name[_Token_index[i]:_Token_index[i+1]]
}
func (i Token) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
func (i Token) IsAnd() bool {
return i == And
}
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/attorney/what-happens-when-you-sign-the-lpa.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('What happens when you sign the LPA', () => {
});

it('as a personal welfare attorney', () => {
cy.visit('/fixtures/attorney?redirect=/what-happens-when-you-sign-the-lpa&lpa-type=hw&progress=signedByCertificateProvider');
cy.visit('/fixtures/attorney?redirect=/what-happens-when-you-sign-the-lpa&lpa-type=personal-welfare&progress=signedByCertificateProvider');

cy.contains('p', "you’re officially saying that you want to be an attorney on")
cy.contains('li', "their personal and medical care")
Expand All @@ -29,7 +29,7 @@ describe('What happens when you sign the LPA', () => {
});

it('as a personal welfare replacement attorney', () => {
cy.visit('/fixtures/attorney?redirect=/what-happens-when-you-sign-the-lpa&lpa-type=hw&progress=signedByCertificateProvider&is-replacement=1');
cy.visit('/fixtures/attorney?redirect=/what-happens-when-you-sign-the-lpa&lpa-type=personal-welfare&progress=signedByCertificateProvider&is-replacement=1');

cy.contains('p', "you’re saying that you want to be a replacement attorney ")
cy.contains('li', "their personal and medical care")
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/donor/check-your-lpa.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('Check the LPA', () => {
});

it('cannot change when personal welfare LPA can be used', () => {
cy.visit('/fixtures?redirect=/check-your-lpa&progress=peopleToNotifyAboutYourLpa&lpa-type=hw');
cy.visit('/fixtures?redirect=/check-your-lpa&progress=peopleToNotifyAboutYourLpa&lpa-type=personal-welfare');

cy.contains('.govuk-summary-list__row', 'When your attorneys can use your LPA')
.contains('Only when I do not have mental capacity')
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/donor/how-should-attorneys-make-decisions.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('How should attorneys make decisions', () => {
it('can choose how attorneys act - Jointly for some decisions, and jointly and severally for other decisions', () => {
cy.contains('h1', 'How should your attorneys make decisions?');

cy.get('input[name="decision-type"]').check('mixed');
cy.get('input[name="decision-type"]').check('jointly-for-some-severally-for-others');
cy.get('#f-mixed-details').type('some details on attorneys');

cy.contains('button', 'Save and continue').click();
Expand All @@ -38,7 +38,7 @@ describe('How should attorneys make decisions', () => {
});

it('errors when details empty', () => {
cy.get('input[name="decision-type"]').check('mixed');
cy.get('input[name="decision-type"]').check('jointly-for-some-severally-for-others');
cy.contains('button', 'Save and continue').click();

cy.get('.govuk-error-summary').within(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('How should replacement attorneys make decisions', () => {
});

it('can choose how replacement attorneys act - Jointly for some decisions, and jointly and severally for other decisions', () => {
cy.get('input[name="decision-type"]').check('mixed');
cy.get('input[name="decision-type"]').check('jointly-for-some-severally-for-others');
cy.get('#f-mixed-details').type('some details on attorneys');

cy.contains('button', 'Save and continue').click();
Expand All @@ -36,7 +36,7 @@ describe('How should replacement attorneys make decisions', () => {
});

it('errors when details empty', () => {
cy.get('input[name="decision-type"]').check('mixed');
cy.get('input[name="decision-type"]').check('jointly-for-some-severally-for-others');
cy.contains('button', 'Save and continue').click();

cy.get('.govuk-error-summary').within(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('How should replacement attorneys step in', () => {
// see https://github.com/alphagov/govuk-frontend/issues/979
cy.checkA11yApp({ rules: { 'aria-allowed-attr': { enabled: false } } });

cy.get('input[name="when-to-step-in"]').check('one');
cy.get('input[name="when-to-step-in"]').check('one-can-no-longer-act');

cy.contains('button', 'Save and continue').click();

Expand All @@ -19,7 +19,7 @@ describe('How should replacement attorneys step in', () => {
});

it('can choose how replacement attorneys step in - some other way', () => {
cy.get('input[name="when-to-step-in"]').check('other');
cy.get('input[name="when-to-step-in"]').check('another-way');
cy.get('#f-other-details').type('some details on when to step in');

cy.contains('button', 'Save and continue').click();
Expand All @@ -38,7 +38,7 @@ describe('How should replacement attorneys step in', () => {
});

it('errors when other and details empty', () => {
cy.get('input[name="when-to-step-in"]').check('other');
cy.get('input[name="when-to-step-in"]').check('another-way');
cy.contains('button', 'Save and continue').click();

cy.get('.govuk-error-summary').within(() => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/donor/life-sustaining-treatment.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Life sustaining treatment', () => {
beforeEach(() => {
cy.visit('/fixtures?redirect=/life-sustaining-treatment&lpa-type=hw');
cy.visit('/fixtures?redirect=/life-sustaining-treatment&lpa-type=personal-welfare');
});

it('can be agreed to', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/donor/lpa-type.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ describe('LPA type', () => {
it('can be submitted', () => {
cy.visit('/fixtures?redirect=/lpa-type&progress=provideYourDetails');

cy.get('#f-lpa-type').check('pfa');
cy.get('#f-lpa-type').check('property-and-affairs');

cy.checkA11yApp();

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/donor/provide-your-details.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Provide your details', () => {
cy.get('[name="language-preference"]').check('en')
cy.contains('button', 'Save and continue').click()

cy.get('#f-lpa-type').check('pfa');
cy.get('#f-lpa-type').check('property-and-affairs');
cy.contains('button', 'Continue').click();

cy.url()
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/donor/want-replacement-attorneys.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Do you want replacement attorneys', () => {
});

it('wants replacement attorneys - acting jointly for some and severally for others', () => {
cy.visit('/fixtures?redirect=/do-you-want-replacement-attorneys&progress=chooseYourAttorneys&attorneys=mixed');
cy.visit('/fixtures?redirect=/do-you-want-replacement-attorneys&progress=chooseYourAttorneys&attorneys=jointly-for-some-severally-for-others');

cy.get('div.govuk-warning-text').should('contain', 'You appointed your attorneys to act jointly for some decisions, and jointly and severally for others.')

Expand Down
2 changes: 1 addition & 1 deletion internal/actor/attorney_decisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
// JointlyForSomeSeverallyForOthers indicates attorneys or replacement
// attorneys should act jointly for some decisions, and jointly and severally
// for other decisions
JointlyForSomeSeverallyForOthers // mixed
JointlyForSomeSeverallyForOthers // jointly-for-some-severally-for-others
)

// AttorneyDecisions contains details about how an attorney or replacement attorney should act, provided by the applicant
Expand Down
4 changes: 2 additions & 2 deletions internal/actor/donor_provided.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type DonorTasks struct {
YourDetails TaskState
ChooseAttorneys TaskState
ChooseReplacementAttorneys TaskState
WhenCanTheLpaBeUsed TaskState // pfa only
LifeSustainingTreatment TaskState // hw only
WhenCanTheLpaBeUsed TaskState // property and affairs only
LifeSustainingTreatment TaskState // personal welfare only
Restrictions TaskState
CertificateProvider TaskState
CheckYourLpa TaskState
Expand Down
10 changes: 7 additions & 3 deletions internal/actor/enum_attorneysact.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/actor/enum_canbeusedwhen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/actor/enum_certificateprovidercarryoutby.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/actor/enum_certificateproviderrelationship.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/actor/enum_certificateproviderrelationshiplength.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/actor/enum_lifesustainingtreatment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3239ba3

Please sign in to comment.