Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
9475fbae
Commit
9475fbae
authored
7 years ago
by
Akihiko Odaki (@fn_aki@pawoo.net)
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Spec Extractor (#3540)
parent
00e61d68
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
spec/lib/extractor_spec.rb
+79
-0
79 additions, 0 deletions
spec/lib/extractor_spec.rb
with
79 additions
and
0 deletions
spec/lib/extractor_spec.rb
0 → 100644
+
79
−
0
View file @
9475fbae
# frozen_string_literal: true
require
'rails_helper'
describe
Extractor
do
describe
'extract_mentions_or_lists_with_indices'
do
it
'returns an empty array if the given string does not have at signs'
do
text
=
'a string without at signs'
extracted
=
Extractor
.
extract_mentions_or_lists_with_indices
(
text
)
expect
(
extracted
).
to
eq
[]
end
it
'does not extract mentions which ends with particular characters'
do
text
=
'@screen_name@'
extracted
=
Extractor
.
extract_mentions_or_lists_with_indices
(
text
)
expect
(
extracted
).
to
eq
[]
end
it
'returns mentions as an array'
do
text
=
'@screen_name'
extracted
=
Extractor
.
extract_mentions_or_lists_with_indices
(
text
)
expect
(
extracted
).
to
eq
[
{
screen_name:
'screen_name'
,
indices:
[
0
,
12
]
}
]
end
it
'yields mentions if a block is given'
do
text
=
'@screen_name'
Extractor
.
extract_mentions_or_lists_with_indices
(
text
)
do
|
screen_name
,
start_position
,
end_position
|
expect
(
screen_name
).
to
eq
'screen_name'
expect
(
start_position
).
to
eq
0
expect
(
end_position
).
to
eq
12
end
end
end
describe
'extract_hashtags_with_indices'
do
it
'returns an empty array if it does not have #'
do
text
=
'a string without hash sign'
extracted
=
Extractor
.
extract_hashtags_with_indices
(
text
)
expect
(
extracted
).
to
eq
[]
end
it
'does not exclude normal hash text before ://'
do
text
=
'#hashtag://'
extracted
=
Extractor
.
extract_hashtags_with_indices
(
text
)
expect
(
extracted
).
to
eq
[
{
hashtag:
'hashtag'
,
indices:
[
0
,
8
]
}
]
end
it
'excludes http://'
do
text
=
'#hashtaghttp://'
extracted
=
Extractor
.
extract_hashtags_with_indices
(
text
)
expect
(
extracted
).
to
eq
[
{
hashtag:
'hashtag'
,
indices:
[
0
,
8
]
}
]
end
it
'excludes https://'
do
text
=
'#hashtaghttps://'
extracted
=
Extractor
.
extract_hashtags_with_indices
(
text
)
expect
(
extracted
).
to
eq
[
{
hashtag:
'hashtag'
,
indices:
[
0
,
8
]
}
]
end
it
'yields hashtags if a block is given'
do
text
=
'#hashtag'
Extractor
.
extract_hashtags_with_indices
(
text
)
do
|
hashtag
,
start_position
,
end_position
|
expect
(
hashtag
).
to
eq
'hashtag'
expect
(
start_position
).
to
eq
0
expect
(
end_position
).
to
eq
8
end
end
end
describe
'extract_cashtags_with_indices'
do
it
'returns []'
do
text
=
'$cashtag'
extracted
=
Extractor
.
extract_cashtags_with_indices
(
text
)
expect
(
extracted
).
to
eq
[]
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment