Skip to content

Commit

Permalink
fix: added "enum" as a possible unit
Browse files Browse the repository at this point in the history
  • Loading branch information
hlinden authored and hansmi committed Jul 4, 2023
1 parent d336ca7 commit 4768530
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions luxwslang/terminology.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math"
"regexp"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -119,5 +120,15 @@ func (*Terminology) ParseMeasurement(text string) (float64, string, error) {
}
}

if _, err := strconv.Atoi(text); err == nil && len(text) == 1 {
var value float64
var unit string

unit = "enum"
value, _ = strconv.ParseFloat(text, 64)

return value, unit, nil
}

return 0, "", fmt.Errorf("unrecognized measurement format %q", text)
}
1 change: 1 addition & 0 deletions luxwslang/terminology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func TestParseMeasurement(t *testing.T) {
{terms: German, input: "100000 kWh", want: 100000, wantUnit: "kWh"},
{terms: German, input: "1 kW", want: 1, wantUnit: "kW"},
{terms: German, input: "16.66 Hz", want: 16.66, wantUnit: "Hz"},
{terms: German, input: "2", want: 2, wantUnit: "enum"},
{terms: English, input: "200 mA", want: 200, wantUnit: "mA"},
{terms: English, input: "3600s", want: 3600, wantUnit: "s"},
{terms: English, input: "36 m³/h", want: 36, wantUnit: "m³/h"},
Expand Down

0 comments on commit 4768530

Please sign in to comment.