Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
D
Donut
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohamad.alturky
Donut
Commits
2b2fbc82
Commit
2b2fbc82
authored
Feb 24, 2024
by
mohamad.alturky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding tests
parent
3ff6fd3a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
244 additions
and
0 deletions
+244
-0
ConvertNestingToConcatenation_test.go
tests/tokenization/ConvertNestingToConcatenation_test.go
+81
-0
GetDirectiveContent_test.go
tests/tokenization/GetDirectiveContent_test.go
+81
-0
ReplaceDirectiveContent_test.go
tests/tokenization/ReplaceDirectiveContent_test.go
+82
-0
No files found.
tests/tokenization/ConvertNestingToConcatenation_test.go
0 → 100644
View file @
2b2fbc82
package
tokenization_test
import
(
// Settings "donut/settings"
Tokenizer
"donut/tokenization"
"testing"
)
func
TestConvertNestingToConcatenation_ShouldReturnTheExpectedResult_WhenTheTemplateContainsNewLinesBetweenDirectives
(
t
*
testing
.
T
)
{
template
:=
`
@template {{ some code.... @exec {{ nothing }} }}
@exec {{ some go code.... }}
@imports {{ "tesing_package" }}
@template {{ some code.... }}
@exec {{ some go code.... }}
`
expectedTemplate
:=
`
@template {{ some code.... }}@exec {{ nothing }}@template{{ }}
@exec {{ some go code.... }}
@imports {{ "tesing_package" }}
@template {{ some code.... }}
@exec {{ some go code.... }}
`
new
:=
""
startingIdx
:=
0
for
{
if
startingIdx
==
len
(
template
)
{
break
}
res
:=
Tokenizer
.
ConvertNestingToConcatenation
(
startingIdx
,
template
,
"exec"
,
"template"
)
startingIdx
=
res
.
TerminatedAt
new
=
new
+
res
.
Template
}
// t.Log(new)
if
new
!=
expectedTemplate
{
t
.
Error
(
"error in getting template"
)
}
}
func
TestConvertNestingToConcatenation_ShouldReturnTheExpectedResult_WhenTheTemplateStacksDirectivesWithNoSpaces
(
t
*
testing
.
T
)
{
template
:=
`
@template {{ some code.... @exec{{nothing}}555@exec{{nothing}} }}@exec {{ some go code.... }}
@template {{ "tesing_package"@exec{{nothing}} }}
@template {{ some code.... }}
@exec {{ some go code.... }}
`
expectedTemplate
:=
`
@template {{ some code.... }}@exec{{nothing}}@template{{555}}@exec{{nothing}}@template{{ }}@exec {{ some go code.... }}
@template {{ "tesing_package"}}@exec{{nothing}}@template{{ }}
@template {{ some code.... }}
@exec {{ some go code.... }}
`
new
:=
""
startingIdx
:=
0
for
{
if
startingIdx
==
len
(
template
)
{
break
}
res
:=
Tokenizer
.
ConvertNestingToConcatenation
(
startingIdx
,
template
,
"exec"
,
"template"
)
startingIdx
=
res
.
TerminatedAt
new
=
new
+
res
.
Template
}
t
.
Log
(
new
)
if
new
!=
expectedTemplate
{
t
.
Error
(
"error in getting template"
)
}
}
tests/tokenization/GetDirectiveContent_test.go
0 → 100644
View file @
2b2fbc82
package
tokenization_test
import
(
Settings
"donut/settings"
Tokenizer
"donut/tokenization"
"testing"
)
func
TestExtractDirectiveContent_ShouldReturnTheExpectedResult_WhenTheTemplateContainsNewLinesBetweenDirectives
(
t
*
testing
.
T
)
{
template
:=
`
@template {{ some code.... }}
@exec {{ some go code.... }}
@imports {{ "tesing_package" }}
@template {{ some code.... }}
@exec {{ some go code.... }}
`
expectedImports
:=
` "tesing_package" `
expectedTemplate
:=
`
@template {{ some code.... }}
@exec {{ some go code.... }}
@template {{ some code.... }}
@exec {{ some go code.... }}
`
result
:=
Tokenizer
.
ExtractDirectiveContent
(
template
,
Settings
.
IMPORT_KEY_WORD
)
if
result
[
0
]
!=
expectedImports
{
t
.
Error
(
"error in getting imports"
)
}
if
result
[
1
]
!=
expectedTemplate
{
t
.
Error
(
"error in getting template"
)
}
}
func
TestExtractDirectiveContent_ShouldReturnTheExpectedResult_WhenTheTemplateContainsSpacesBetweenDirectives
(
t
*
testing
.
T
)
{
template
:=
`
@template {{ some code.... }} @exec {{ some go code.... }} @imports {{"tesing_package" }} @template {{ some code.... }} @exec {{ some go code.... }}
`
expectedImports
:=
`"tesing_package" `
expectedTemplate
:=
`
@template {{ some code.... }} @exec {{ some go code.... }} @template {{ some code.... }} @exec {{ some go code.... }}
`
result
:=
Tokenizer
.
ExtractDirectiveContent
(
template
,
Settings
.
IMPORT_KEY_WORD
)
if
result
[
0
]
!=
expectedImports
{
t
.
Error
(
"error in getting imports"
)
}
if
result
[
1
]
!=
expectedTemplate
{
t
.
Error
(
"error in getting template"
)
}
}
func
TestExtractDirectiveContent_ShouldReturnTheExpectedResult_WhenTheTemplateStacksDirectivesWithNoSpaces
(
t
*
testing
.
T
)
{
template
:=
`
@template {{ some code.... }}@exec {{ some go code.... }}54646@imports{{ 8 "tesing_package"}}@template{{ some code.... }}@exec{{ some go code.... }}
`
expectedImports
:=
` 8 "tesing_package"`
expectedTemplate
:=
`
@template {{ some code.... }}@exec {{ some go code.... }}54646@template{{ some code.... }}@exec{{ some go code.... }}
`
result
:=
Tokenizer
.
ExtractDirectiveContent
(
template
,
Settings
.
IMPORT_KEY_WORD
)
if
result
[
0
]
!=
expectedImports
{
t
.
Error
(
"error in getting imports"
)
}
if
result
[
1
]
!=
expectedTemplate
{
t
.
Error
(
"error in getting template"
)
t
.
Log
(
result
[
1
])
}
}
tests/tokenization/ReplaceDirectiveContent_test.go
0 → 100644
View file @
2b2fbc82
package
tokenization_test
import
(
Tokenizer
"donut/tokenization"
"testing"
)
func
TestReplaceDirectiveContentWithTemplateWithNewLinesBetweenDirectives
(
t
*
testing
.
T
)
{
template
:=
`----
@template {{ some code.... }}
@exec {{
for i := 0; i < 7; i++ {
@inject {{ string(i) }}
}
}}
@template {{ some code.... }}
@exec {{ some go code.... }}
------
`
expectedTemplate
:=
`----
@template {{ some code.... }}
@exec {{
for i := 0; i < 7; i++ {
code = code + string(i)
}
}}
@template {{ some code.... }}
@exec {{ some go code.... }}
------
`
result
:=
Tokenizer
.
ReplaceDirectiveContent
(
template
,
"@inject"
,
Identity
)
t
.
Log
(
result
)
if
result
!=
expectedTemplate
{
t
.
Error
(
"error in getting template"
)
}
}
func
TestReplaceDirectiveContentWithTemplateWithSpacesBetweenDirectives
(
t
*
testing
.
T
)
{
template
:=
`----
@template {{ some code.... }}
@exec {{
for i := 0; i < 7; i++ { @inject {{ string(i) }} }
}}
@template {{ some code.... }}
@exec {{ some go code.... }}
------
`
expectedTemplate
:=
`----
@template {{ some code.... }}
@exec {{
for i := 0; i < 7; i++ { code = code + string(i) }
}}
@template {{ some code.... }}
@exec {{ some go code.... }}
------
`
result
:=
Tokenizer
.
ReplaceDirectiveContent
(
template
,
"@inject"
,
Identity
)
t
.
Log
(
result
)
if
result
!=
expectedTemplate
{
t
.
Error
(
"error in getting template"
)
}
}
func
Identity
(
text
string
)
string
{
return
"code = "
+
" code + "
+
text
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment