Skip to content

Commit

Permalink
Added tests to CheckTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
sandypadmanabhan committed Apr 26, 2021
1 parent b553329 commit 6d9f645
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
Binary file added NOMIS/debug.test
Binary file not shown.
4 changes: 2 additions & 2 deletions NOMIS/nomis.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func main() {
Next: &mapData,
}

createDocument(ctx, datasetDoc, session, "datasets")q
createDocument(ctx, datasetDoc, session, "datasets")
createDocument(ctx, censusEditionData, session, "editions")
createDocument(ctx, censusInstances, session, "instances")
}
Expand Down Expand Up @@ -346,7 +346,7 @@ func CheckSubString(existingStr string) (string, error) {
}

func CheckTitle(sourceStr string) (string, error) {
valueCheck, err := regexp.Compile(`^[\d|\D].*?\-\s([\d|\D].*)$`)
valueCheck, err := regexp.Compile(`^[\d|\D].*?\-\s*([\d|\D].*)$`)
if err != nil {
return "", err
}
Expand Down
53 changes: 52 additions & 1 deletion NOMIS/nomis_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main_test

import (
"testing"

nomis "github.com/ONSdigital/dp-dataset-api/NOMIS"
. "github.com/smartystreets/goconvey/convey"
"testing"
)

func TestCheckSubString(t *testing.T) {
Expand Down Expand Up @@ -60,3 +61,53 @@ func TestCheckSubString(t *testing.T) {
})
}
}
func TestCheckTitle(t *testing.T) {
cases := []struct {
Description string
GivenString string
ExpectedResult string
}{
{
"Given a title ",
"QS102EW - Population density",
"Population density",
},
{
"Given a title with multiple hyphens",
"OT102EW - Population density (Out of term-time population)",
"Population density (Out of term-time population)",
},
{
"Given a title with multiple hyphens",
"DC6104EWla - Industry by sex by age - Communal establishment residents",
"Industry by sex by age - Communal establishment residents",
},
{
"Given a title with multiple hyphens and multiple space",
"DC6104EWla to AW1234WE - Industry by sex by age - Communal establishment residents",
"Industry by sex by age - Communal establishment residents",
},
{
"Given a title with no space before the first hyphens",
"AW1234WE- Industry by sex by age - Communal establishment residents",
"Industry by sex by age - Communal establishment residents",
},
{
"Given a string no matches",
"you can get the information from " +
"hello world",
"you can get the information from " +
"hello world",
},
}

for _, test := range cases {
Convey(test.Description, t, func() {
Convey("Then the CheckTitle function should return the expected string", func() {
actualString, err := nomis.CheckTitle(test.GivenString)
So(err, ShouldBeNil)
So(actualString, ShouldResemble, test.ExpectedResult)
})
})
}
}

0 comments on commit 6d9f645

Please sign in to comment.