-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add Script Languages enum and coresponding unit tests 📝
- Loading branch information
1 parent
b2eb9d1
commit e2ce580
Showing
2 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package scriptlanguage | ||
|
||
// ScriptLanguage represents the different scripting languages supported by Elasticsearch. | ||
// | ||
// ScriptLanguage is a string type used to specify the language of a script in Elasticsearch queries. | ||
// It defines various options for scripting, allowing users to perform advanced calculations, | ||
// filtering, and custom scoring within search queries. | ||
// | ||
// Example usage: | ||
// | ||
// var lang ScriptLanguage = Painless | ||
// | ||
// // Use lang in a script configuration | ||
// | ||
// Constants: | ||
// - Painless: The default and most efficient scripting language in Elasticsearch. | ||
// - Expression: A lightweight, fast scripting language for numeric calculations. | ||
// - Mustache: A template-based scripting language used for rendering responses. | ||
// - Java: A scripting option that allows Java code execution within queries. | ||
type ScriptLanguage string | ||
|
||
const ( | ||
// Painless is the default scripting language in Elasticsearch, optimized for performance and security. | ||
Painless ScriptLanguage = "painless" | ||
|
||
// Expression is a simple and fast scripting language for numeric computations. | ||
Expression ScriptLanguage = "expression" | ||
|
||
// Mustache is a templating language used for response rendering in Elasticsearch. | ||
Mustache ScriptLanguage = "mustache" | ||
|
||
// Java allows executing Java-based scripts in Elasticsearch. | ||
Java ScriptLanguage = "java" | ||
) | ||
|
||
// String returns the string representation of the ScriptLanguage. | ||
func (scriptLanguage ScriptLanguage) String() string { | ||
return string(scriptLanguage) | ||
} |
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,27 @@ | ||
package scriptlanguage_test | ||
|
||
import ( | ||
"testing" | ||
|
||
ScriptLanguage "github.com/Trendyol/es-query-builder/es/enums/script-language" | ||
|
||
"github.com/Trendyol/es-query-builder/test/assert" | ||
) | ||
|
||
func Test_ScriptLanguageString(t *testing.T) { | ||
tests := []struct { | ||
scriptLanguage ScriptLanguage.ScriptLanguage | ||
result string | ||
}{ | ||
{ScriptLanguage.Painless, "painless"}, | ||
{ScriptLanguage.Expression, "expression"}, | ||
{ScriptLanguage.Mustache, "mustache"}, | ||
{ScriptLanguage.Java, "java"}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.result, func(t *testing.T) { | ||
assert.Equal(t, test.result, test.scriptLanguage.String()) | ||
}) | ||
} | ||
} |