Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/sections/sections-pattern.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { SECTION_SEGMENT_BREAKDOWN } from './sections-pattern'

describe('SECTION_SEGMENT_BREAKDOWN', () => {
it.each(['320010003', '320012001', '320291132'])(
'matches the full abroad section id %s',
(id) => {
const groups = SECTION_SEGMENT_BREAKDOWN.exec(id)?.groups
expect(groups?.abroadRegionCode).toBe('32')
expect(groups?.countryCode).toBe(id.slice(2, 5))
expect(groups?.sectionCodeAbroad).toBe(id.slice(6))
},
)

it('still matches abroad region and country segments', () => {
expect(SECTION_SEGMENT_BREAKDOWN.exec('32')?.groups?.abroadRegionCode).toBe(
'32',
)
expect(SECTION_SEGMENT_BREAKDOWN.exec('32001')?.groups?.countryCode).toBe(
'001',
)
})

it('still matches domestic segments', () => {
const groups = SECTION_SEGMENT_BREAKDOWN.exec('010100001')?.groups
expect(groups?.electionRegionCode).toBe('01')
expect(groups?.sectionCodeDomestic).toBe('001')
})
})
2 changes: 1 addition & 1 deletion src/sections/sections-pattern.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const SECTION_SEGMENT_BREAKDOWN =
/^(?<electionRegionCode>0[1-9]|[12][0-9]|3[01])(?:(?<municipalityCode>[0-9]{2})(?:(?<cityRegionCode>[0-9]{2})(?<sectionCodeDomestic>[0-9]{3})?)?)?$|^(?<abroadRegionCode>32)(?:(?<countryCode>[0-9]{3})(?:0(?<sectionCodeAbroad>[0-9]{3})?)?)?$/
/^(?<electionRegionCode>0[1-9]|[12][0-9]|3[01])(?:(?<municipalityCode>[0-9]{2})(?:(?<cityRegionCode>[0-9]{2})(?<sectionCodeDomestic>[0-9]{3})?)?)?$|^(?<abroadRegionCode>32)(?:(?<countryCode>[0-9]{3})(?:[0-9](?<sectionCodeAbroad>[0-9]{3})?)?)?$/
Loading