Repository: bxcodec/faker
Pull request #155 (2022-01-22 08:02:36)

Support for Emoticons
Support for Emoticons
But still using `lang` tag

Usage:
```go
StringEMJ string `faker:"lang=emj"`
```

Output:
```
StringEMJ:🐅😄🕢🍪🐡
```
			   

bxcodec: Hey @geshtng , could you help to rebase your PR. I think it's conflict

Patch:
diff --git a/faker.go b/faker.go
index d237a61..4da208d 100644
--- a/faker.go
+++ b/faker.go
@@ -66,6 +66,8 @@ var (
 	LangJPN = langRuneBoundary{12353, 12534, []rune{12436, 12437, 12438, 12439, 12440, 12441, 12442, 12443, 12444, 12445, 12446, 12447, 12448}}
 	// LangKOR is for korean Hangul language
 	LangKOR = langRuneBoundary{44032, 55203, nil}
+	// EmotEMJ is for emoticons
+	EmotEMJ = langRuneBoundary{126976, 129535, nil}
 )
 
 // Supported tags
@@ -330,7 +332,7 @@ func SetRandomStringLength(size int) error {
 	return nil
 }
 
-// SetStringLang sets language of random string generation (LangENG, LangCHI, LangRUS, LangJPN, LangKOR)
+// SetStringLang sets language of random string generation (LangENG, LangCHI, LangRUS, LangJPN, LangKOR, EmotEMJ)
 func SetStringLang(l langRuneBoundary) {
 	lang = l
 }
@@ -961,6 +963,8 @@ func extractLangFromTag(tag string) (*langRuneBoundary, error) {
 		return &LangJPN, nil
 	case "kor":
 		return &LangKOR, nil
+	case "emj":
+		return &EmotEMJ, nil
 	default:
 		return &LangENG, nil
 	}


Test patch:
diff --git a/example_with_tags_lang_test.go b/example_with_tags_lang_test.go
index c3a6255..be6b097 100644
--- a/example_with_tags_lang_test.go
+++ b/example_with_tags_lang_test.go
@@ -15,6 +15,7 @@ func Example_withTagsLang() {
 		StringRUS string `faker:"lang=rus"`
 		StringJPN string `faker:"lang=jpn"`
 		StringKOR string `faker:"lang=kor"`
+		StringEMJ string `faker:"lang=emj"`
 	}
 
 	a := SomeStruct{}
@@ -29,6 +30,7 @@ func Example_withTagsLang() {
 			   StringRUS:ваЩфз
 			   StringJPN:びゃほぱヒてふ
 			   StringKOR:텻밚쨋큊몉
+			   StringEMJ:🐅😄🕢🍪🐡
 		   }
 	*/
 }
diff --git a/faker_test.go b/faker_test.go
index eef3064..c86f63b 100644
--- a/faker_test.go
+++ b/faker_test.go
@@ -20,10 +20,11 @@ const (
 	someStructWithLenAndLangRUS = 15
 	someStructWithLenAndLangJPN = 20
 	someStructWithLenAndLangKOR = 25
+	someStructWithLenAndEmotEMJ = 50
 )
 
 var (
-	langCorrectTagsMap = map[string]langRuneBoundary{"lang=eng": LangENG, "lang=chi": LangCHI, "lang=rus": LangRUS, "lang=jpn": LangJPN, "lang=kor": LangKOR}
+	langCorrectTagsMap = map[string]langRuneBoundary{"lang=eng": LangENG, "lang=chi": LangCHI, "lang=rus": LangRUS, "lang=jpn": LangJPN, "lang=kor": LangKOR, "lang=emj": EmotEMJ}
 	langUncorrectTags  = [3]string{"lang=", "lang", "lng=eng"}
 
 	lenCorrectTags   = [3]string{"len=4", "len=5", "len=10"}
@@ -142,6 +143,7 @@ type SomeStructWithLang struct {
 	ValueRUS string `faker:"lang=rus"`
 	ValueJPN string `faker:"lang=jpn"`
 	ValueKOR string `faker:"lang=kor"`
+	ValueEMJ string `faker:"lang=emj"`
 
 	ValueWithUndefinedLang string `faker:"lang=und"`
 }
@@ -152,6 +154,7 @@ type SomeStructWithLenAndLang struct {
 	ValueRUS string ` faker:"len=15, lang=rus"`
 	ValueJPN string ` faker:"len=20, lang=jpn"`
 	ValueKOR string ` faker:"len=25, lang=kor"`
+	ValueEMJ string ` faker:"len=50, lang=emj"`
 }
 
 func (s SomeStruct) String() string {
@@ -642,6 +645,10 @@ func TestLang(t *testing.T) {
 	if err != nil {
 		t.Error(err.Error())
 	}
+	err = isStringLangCorrect(someStruct.ValueEMJ, EmotEMJ)
+	if err != nil {
+		t.Error(err.Error())
+	}
 
 	err = isStringLangCorrect(someStruct.ValueWithUndefinedLang, LangENG)
 	if err != nil {
@@ -793,6 +800,15 @@ func TestLangWithLen(t *testing.T) {
 	if korLen != someStructWithLenAndLangKOR {
 		t.Errorf("Got %d, but expected to be %d as a string len", korLen, someStructWithLenAndLangKOR)
 	}
+
+	err = isStringLangCorrect(someStruct.ValueEMJ, EmotEMJ)
+	if err != nil {
+		t.Error(err.Error())
+	}
+	emjLen := utfLen(someStruct.ValueEMJ)
+	if emjLen != someStructWithLenAndEmotEMJ {
+		t.Errorf("Got %d, but expected to be %d as a string len", emjLen, someStructWithLenAndEmotEMJ)
+	}
 }
 
 func isStringLangCorrect(value string, lang langRuneBoundary) error {