-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Gemfile(.lock), add rspec tests for bangs jsons, add rspec to CI
- Loading branch information
1 parent
a64bf8d
commit e739d93
Showing
6 changed files
with
137 additions
and
1 deletion.
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 @@ | ||
BUNDLE_PATH: ./vendor/bundle |
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ jobs: | |
- name: Validate JSON | ||
uses: walbo/[email protected] | ||
with: | ||
files: ./data/bangs.json | ||
files: data/*.json | ||
|
||
# optional, defaults to `$schema` in your JSON file | ||
schema: ./data/bangs.schema.json | ||
|
@@ -37,3 +37,17 @@ jobs: | |
|
||
# optional, default: true | ||
allow-union-types: true | ||
run-rspec-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
# Not needed with a .ruby-version file | ||
ruby-version: 3.0 | ||
# runs 'bundle install' and caches installed gems automatically | ||
bundler-cache: true | ||
- name: Run tests | ||
run: | | ||
bundle exec rspec |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
.DS_Store | ||
/vendor |
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,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem "json" | ||
gem "rspec", "~> 3.13" | ||
gem 'addressable', '~> 2.8', '>= 2.8.6' |
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,33 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.8.6) | ||
public_suffix (>= 2.0.2, < 6.0) | ||
diff-lcs (1.5.1) | ||
json (2.7.1) | ||
public_suffix (5.0.4) | ||
rspec (3.13.0) | ||
rspec-core (~> 3.13.0) | ||
rspec-expectations (~> 3.13.0) | ||
rspec-mocks (~> 3.13.0) | ||
rspec-core (3.13.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-expectations (3.13.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-mocks (3.13.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-support (3.13.1) | ||
|
||
PLATFORMS | ||
ruby | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
addressable (~> 2.8, >= 2.8.6) | ||
json | ||
rspec (~> 3.13) | ||
|
||
BUNDLED WITH | ||
2.5.4 |
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,82 @@ | ||
require "json" | ||
require "rspec" | ||
require "addressable" | ||
|
||
bangs_json = JSON.parse(File.read("data/bangs.json")) | ||
bang_triggers = bangs_json.map{|b| b["t"]} | ||
|
||
kagi_bangs_json = JSON.parse(File.read("data/kagi_bangs.json")) | ||
kagi_triggers = kagi_bangs_json.map{|b| b["t"]} | ||
|
||
assist_bangs_json = JSON.parse(File.read("data/assistant_bangs.json")) | ||
assistant_triggers = assist_bangs_json.map{|b| b["t"]} | ||
|
||
def find_dups(*arr) | ||
arr.map{ |a| a.uniq } | ||
.flatten | ||
.group_by { |element| element } | ||
.select { |k, v| v.size > 1 } | ||
.keys | ||
end | ||
|
||
def match_domains(bangs) | ||
bangs.each do |bang| | ||
next if bang["u"].start_with?("/") | ||
|
||
it "domains match template urls (#{bang["s"]})" do | ||
template = bang["u"].gsub("{{{s}}}", "example").gsub("www.", "") | ||
uri = Addressable::URI.parse(template) | ||
domain = bang["d"].gsub("{{{s}}}", "example").gsub("www.", "") | ||
|
||
expect(domain).to eq(uri.host) | ||
end | ||
end | ||
end | ||
|
||
describe "bangs.json" do | ||
it "doesn't have duplicate bang triggers" do | ||
dups = find_dups(bang_triggers) | ||
|
||
expect(dups).to be_empty, "Duplicate(s) found: #{dups.join(", ")}" | ||
end | ||
|
||
it "and kagi_bangs.json don't have duplicate bang triggers" do | ||
dups = find_dups(bang_triggers, kagi_triggers) | ||
|
||
expect(dups).to be_empty, "Duplicate(s) found: #{dups.join(", ")}" | ||
end | ||
|
||
it "and assist_bangs.json don't have duplicate bang triggers" do | ||
dups = find_dups(bang_triggers, assistant_triggers) | ||
|
||
expect(dups).to be_empty, "Duplicate(s) found: #{dups.join(", ")}" | ||
end | ||
|
||
match_domains(bangs_json) | ||
end | ||
|
||
describe "kagi_bangs.json" do | ||
it "doesn't have duplicate bang triggers" do | ||
dups = find_dups(kagi_triggers) | ||
|
||
expect(dups).to be_empty, "Duplicate(s) found: #{dups.join(", ")}" | ||
end | ||
|
||
it "and assistant_bangs.json don't have duplicate bang triggers" do | ||
dups = find_dups(kagi_triggers, assistant_triggers) | ||
|
||
expect(dups).to be_empty, "Duplicate trigger(s) found: #{dups.join(", ")}" | ||
end | ||
|
||
match_domains(kagi_bangs_json) | ||
end | ||
|
||
describe "assistant_bangs.json" do | ||
it "doesn't have duplicate bang triggers" do | ||
dups = find_dups(assistant_triggers) | ||
|
||
expect(dups).to be_empty, "Duplicate(s) found: #{dups.join(", ")}" | ||
end | ||
|
||
match_domains(assist_bangs_json) | ||
end |