diff --git a/.travis.yml b/.travis.yml index 3751d20..f74dec4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,4 @@ install: script: - crystal spec + - bin/crytic --preamble "" diff --git a/Makefile b/Makefile index 53ff128..909421d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PHONY: app-container clean check test +PHONY: app-container clean check test deps crytic CR_FLAGS="--release --static --no-debug -Dtrace" PUBLIC_PORT=9000 @@ -12,5 +12,11 @@ clean: check: crystal build --no-codegen src/**/*.cr -test: - crystal spec +deps: + shards install + +test: deps + crystal spec -- -p 3 + +crytic: deps + bin/crytic --preamble "" diff --git a/spec/gopher/resolver_spec.cr b/spec/gopher/resolver_spec.cr new file mode 100644 index 0000000..09b3b37 --- /dev/null +++ b/spec/gopher/resolver_spec.cr @@ -0,0 +1,24 @@ +require "../spec_helper" + +class SpecResolver < Gopher::Resolver + def resolve(_req) + Gopher::Response.error("BOOM") + end + + def menu_entry_type + Gopher::MenuEntryType::Error + end +end + +module Gopher + describe Resolver do + describe "default values" do + it "are correct" do + resolver = SpecResolver.new + + expect(resolver.default_host).must_equal("localhost") + expect(resolver.default_port).must_equal(70_u16) + end + end + end +end diff --git a/spec/gopher/resolvers/directory_resolver_spec.cr b/spec/gopher/resolvers/directory_resolver_spec.cr index f83cee7..f373203 100644 --- a/spec/gopher/resolvers/directory_resolver_spec.cr +++ b/spec/gopher/resolvers/directory_resolver_spec.cr @@ -30,16 +30,18 @@ module Gopher expect(menu.entries.size > 0).must_equal(true) end - it "lists .txt files as text entries" do - result = dr.resolve(req) - menu = result.value.as Menu + it "lists text files as text entries" do + DirectoryResolver::TEXT_EXTENSIONS.each do |ext| + result = dr.resolve(req) + menu = result.value.as Menu - ipsum = menu.entries.count do |entry| - entry.entry_type == MenuEntryType::TextFile && - entry.selector == "/1files/0ipsum.txt" - end + ipsum = menu.entries.count do |entry| + entry.entry_type == MenuEntryType::TextFile && + entry.selector == "/1files/0test#{ext}" + end - expect(ipsum).must_equal(1) + expect(ipsum).must_equal(1) + end end it "includes submenus" do diff --git a/spec/resources/example_directory/.gophermap b/spec/resources/example_directory/.gophermap index d0fea51..ea6cc7a 100644 --- a/spec/resources/example_directory/.gophermap +++ b/spec/resources/example_directory/.gophermap @@ -3,3 +3,23 @@ i 0Hipster Ipsum 0ipsum.txt %HOST% %PORT% 1Games /1games %HOST% %PORT% 1Other Directory /1looks_like_a_file_but_is_a.directory %HOST% %PORT% +i Test text files: +0c 0test.c %HOST% %PORT% +0C 0test.C %HOST% %PORT% +0cpp 0test.cpp %HOST% %PORT% +0cs 0test.cs %HOST% %PORT% +0cr 0test.cr %HOST% %PORT% +0d 0test.d %HOST% %PORT% +0el 0test.el %HOST% %PORT% +0fs 0test.fs %HOST% %PORT% +0html 0test.html %HOST% %PORT% +0xml 0test.xml %HOST% %PORT% +0json 0test.json %HOST% %PORT% +0txt 0test.txt %HOST% %PORT% +0md 0test.md %HOST% %PORT% +0markdown 0test.markdown %HOST% %PORT% +0rb 0test.rb %HOST% %PORT% +0py 0test.py %HOST% %PORT% +0sh 0test.sh %HOST% %PORT% +0rtf 0test.rtf %HOST% %PORT% +0js 0test.js %HOST% %PORT% diff --git a/spec/resources/example_directory/test.c b/spec/resources/example_directory/test.c new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.cpp b/spec/resources/example_directory/test.cpp new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.cr b/spec/resources/example_directory/test.cr new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.cs b/spec/resources/example_directory/test.cs new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.d b/spec/resources/example_directory/test.d new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.el b/spec/resources/example_directory/test.el new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.fs b/spec/resources/example_directory/test.fs new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.html b/spec/resources/example_directory/test.html new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.js b/spec/resources/example_directory/test.js new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.markdown b/spec/resources/example_directory/test.markdown new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.md b/spec/resources/example_directory/test.md new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.py b/spec/resources/example_directory/test.py new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.rb b/spec/resources/example_directory/test.rb new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.rtf b/spec/resources/example_directory/test.rtf new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.sh b/spec/resources/example_directory/test.sh new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.txt b/spec/resources/example_directory/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.xml b/spec/resources/example_directory/test.xml new file mode 100644 index 0000000..e69de29 diff --git a/src/gopher/resolvers/directory_resolver.cr b/src/gopher/resolvers/directory_resolver.cr index 7846d07..01bec13 100644 --- a/src/gopher/resolvers/directory_resolver.cr +++ b/src/gopher/resolvers/directory_resolver.cr @@ -8,7 +8,7 @@ module Gopher PORT_MARKER = "%PORT%" IMAGE_EXTENSIONS = [".jpg", ".gif", ".bmp", ".png", ".jpeg", ".tif", ".tiff", ".tga", ".ico"] BINARY_EXTENSIONS = IMAGE_EXTENSIONS + [".zip", ".tar", ".gz", ".bz2", ".doc", ".xls", ".ppt", ".exe", ".wav", ".mp3", ".ogg"] - TEXT_EXTENSIONS = [".c", ".C", ".cpp", ".cs", ".cr", ".d", ".el", ".fs", ".html", ".xml", ".json", ".txt", ".md", ".markdown", ".rb", ".py", ".sh", ".js", ".rtf"] + TEXT_EXTENSIONS = [".c", ".cpp", ".cs", ".cr", ".d", ".el", ".fs", ".html", ".xml", ".json", ".txt", ".md", ".markdown", ".rb", ".py", ".sh", ".js", ".rtf"] def initialize(@root_path : String, @root_selector : String, config) super(config)