-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from michimani/issue/1/support-more-translate-o…
…ptions Draft: Issue/1/support more translate options
- Loading branch information
Showing
5 changed files
with
277 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,76 @@ | ||
package types | ||
|
||
type SplitSentences string | ||
|
||
const ( | ||
// no splitting at all, whole input is treated as one sentence | ||
SplitSentencesNoSplit = "0" | ||
|
||
// splits on interpunction and on newlines (default) | ||
SplitSentencesSplit = "1" | ||
|
||
// splits on interpunction only, ignoring newlines | ||
SplitSentencesNoNewLines = "nonewlines" | ||
) | ||
|
||
func (s SplitSentences) Valid() bool { | ||
if s != SplitSentencesNoSplit && s != SplitSentencesSplit && s != SplitSentencesNoNewLines { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
type PreserveFormatting string | ||
|
||
const ( | ||
// default | ||
PreserveFormattingDisabled = "0" | ||
|
||
PreserveFormattingEnabled = "1" | ||
) | ||
|
||
func (p PreserveFormatting) Valid() bool { | ||
if p != PreserveFormattingDisabled && p != PreserveFormattingEnabled { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
type Formality string | ||
|
||
const ( | ||
FormalityDefault = "default" | ||
|
||
// for a more formal language | ||
FormalityMore = "more" | ||
|
||
// for a more informal language | ||
FormalityLess = "less" | ||
) | ||
|
||
var validTargetLanguages map[TargetLangCode]struct{} = map[TargetLangCode]struct{}{ | ||
TargetLangDE: {}, | ||
TargetLangFR: {}, | ||
TargetLangIT: {}, | ||
TargetLangES: {}, | ||
TargetLangNL: {}, | ||
TargetLangPL: {}, | ||
TargetLangPTPT: {}, | ||
TargetLangPTBR: {}, | ||
TargetLangRU: {}, | ||
} | ||
|
||
func (f Formality) Valid(t TargetLangCode) bool { | ||
// This feature only works for certain target languages. | ||
if _, ok := validTargetLanguages[t]; !ok { | ||
return false | ||
} | ||
|
||
if f != FormalityDefault && f != FormalityMore && f != FormalityLess { | ||
return false | ||
} | ||
|
||
return true | ||
} |
This file contains 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,137 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/michimani/deepl-sdk-go/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSplitSentencesValid(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
s types.SplitSentences | ||
exect bool | ||
}{ | ||
{ | ||
name: "SplitSentencesNoSplit", | ||
s: types.SplitSentencesNoSplit, | ||
exect: true, | ||
}, | ||
{ | ||
name: "SplitSentencesSplit", | ||
s: types.SplitSentencesSplit, | ||
exect: true, | ||
}, | ||
{ | ||
name: "SplitSentencesNoNewLines", | ||
s: types.SplitSentencesNoNewLines, | ||
exect: true, | ||
}, | ||
{ | ||
name: "invalid value", | ||
s: types.SplitSentences("invalid value"), | ||
exect: false, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(tt *testing.T) { | ||
b := c.s.Valid() | ||
|
||
assert.Equal(tt, b, c.exect) | ||
}) | ||
} | ||
} | ||
|
||
func TestPreserveFormattingValid(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
s types.PreserveFormatting | ||
exect bool | ||
}{ | ||
{ | ||
name: "PreserveFormattingDisabled", | ||
s: types.PreserveFormattingDisabled, | ||
exect: true, | ||
}, | ||
{ | ||
name: "PreserveFormattingEnabled", | ||
s: types.PreserveFormattingEnabled, | ||
exect: true, | ||
}, | ||
{ | ||
name: "invalid value", | ||
s: types.PreserveFormatting("invalid value"), | ||
exect: false, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(tt *testing.T) { | ||
b := c.s.Valid() | ||
|
||
assert.Equal(tt, b, c.exect) | ||
}) | ||
} | ||
} | ||
|
||
func TestFormalityValid(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
s types.Formality | ||
l types.TargetLangCode | ||
exect bool | ||
}{ | ||
{ | ||
name: "FormalityDefault", | ||
s: types.FormalityDefault, | ||
l: types.TargetLangRU, | ||
exect: true, | ||
}, | ||
{ | ||
name: "FormalityMore", | ||
s: types.FormalityMore, | ||
l: types.TargetLangRU, | ||
exect: true, | ||
}, | ||
{ | ||
name: "FormalityLess", | ||
s: types.FormalityLess, | ||
l: types.TargetLangRU, | ||
exect: true, | ||
}, | ||
{ | ||
name: "invalid value", | ||
s: types.Formality("invalid value"), | ||
l: types.TargetLangRU, | ||
exect: false, | ||
}, | ||
{ | ||
name: "FormalityDefault with not supported target language", | ||
s: types.FormalityDefault, | ||
l: types.TargetLangJA, | ||
exect: false, | ||
}, | ||
{ | ||
name: "FormalityMore with not supported target language", | ||
s: types.FormalityMore, | ||
l: types.TargetLangJA, | ||
exect: false, | ||
}, | ||
{ | ||
name: "FormalityLess with not supported target language", | ||
s: types.FormalityLess, | ||
l: types.TargetLangJA, | ||
exect: false, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(tt *testing.T) { | ||
b := c.s.Valid(c.l) | ||
|
||
assert.Equal(tt, b, c.exect) | ||
}) | ||
} | ||
} |