Remove conanfile. Update mustache specification jsons. Remove compilation warnings. Update CMake version. Change test framework to Catch2.

This commit is contained in:
Igor Mróz 2020-10-18 18:59:15 +02:00
parent 36561cecf5
commit 7b8b72bd11
No known key found for this signature in database
GPG Key ID: F32A9B94C1DC1AF2
28 changed files with 18054 additions and 1572 deletions

View File

@ -1,11 +1,6 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.15)
project (crow_all)
if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(Tcmalloc)
@ -38,16 +33,15 @@ else()
find_package( Boost 1.52 COMPONENTS system thread REQUIRED )
endif()
include_directories( ${Boost_INCLUDE_DIR} )
include_directories(${Boost_INCLUDE_DIR})
set(PROJECT_INCLUDE_DIR
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/include
)
include_directories("${PROJECT_INCLUDE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}")
#add_subdirectory(src)
add_subdirectory(examples)
if (MSVC)
@ -67,7 +61,7 @@ else()
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/amalgamate/crow_all.h ${PROJECT_SOURCE_DIR}/amalgamate
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/amalgamate
DEPENDS ${PROJECT_SOURCE_DIR}/include/*.h ${PROJECT_SOURCE_DIR}/include/crow/*.h
)
)
add_custom_target(amalgamation ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/amalgamate/crow_all.h)
endif()

View File

@ -1,27 +0,0 @@
from conans import ConanFile, CMake
class CrowConan(ConanFile):
name = "Crow"
version = "0.1"
url = "https://github.com/ipkn/crow"
license = "MIT; see https://github.com/ipkn/crow/blob/master/LICENSE"
generators = "cmake"
settings = "os", "compiler", "build_type", "arch"
requires = (("Boost/1.60.0@lasote/stable"),
("OpenSSL/1.0.2i@lasote/stable"))
# No exports necessary
def source(self):
# this will create a hello subfolder, take it into account
self.run("git clone https://github.com/ipkn/crow.git")
def build(self):
cmake = CMake(self.settings)
self.run('cmake %s/crow %s' % (self.conanfile_directory, cmake.command_line))
self.run("cmake --build . %s" % cmake.build_config)
self.run("make")
def package(self):
self.copy("*.h", dst="include", src="amalgamate")

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.15)
project (crow_examples)
if (MSVC)
@ -27,7 +27,6 @@ add_custom_command(OUTPUT ws.html
add_custom_target(example_ws_copy ALL DEPENDS ws.html)
add_executable(example example.cpp)
#target_link_libraries(example crow)
target_link_libraries(example ${Boost_LIBRARIES})
target_link_libraries(example ${CMAKE_THREAD_LIBS_INIT})
@ -37,7 +36,6 @@ endif(Tcmalloc_FOUND)
add_executable(example_with_all example_with_all.cpp)
add_dependencies(example_with_all amalgamation)
#target_link_libraries(example crow)
target_link_libraries(example_with_all ${Boost_LIBRARIES})
target_link_libraries(example_with_all ${CMAKE_THREAD_LIBS_INIT})
@ -58,6 +56,4 @@ add_custom_command(OUTPUT example_chat.html
)
add_custom_target(example_chat_copy ALL DEPENDS example_chat.html)
#SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pg" )
#SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -pg" )
endif()

View File

@ -59,9 +59,6 @@ namespace crow
void run()
{
if (concurrency_ < 0)
concurrency_ = 1;
for(int i = 0; i < concurrency_; i++)
io_service_pool_.emplace_back(new boost::asio::io_service());
get_cached_date_str_pool_.resize(concurrency_);

View File

@ -393,6 +393,7 @@ namespace crow
message_.clear();
}
}
break;
case 1: // Text
{
is_binary_ = false;

View File

@ -1,28 +1,18 @@
cmake_minimum_required(VERSION 2.8)
project (crow_test)
cmake_minimum_required(VERSION 3.15)
project(crow_test)
set(TEST_SRCS
unittest.cpp
unittest.cpp
)
add_executable(unittest ${TEST_SRCS})
#target_link_libraries(unittest crow)
target_link_libraries(unittest ${Boost_LIBRARIES})
target_link_libraries(unittest ${CMAKE_THREAD_LIBS_INIT})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# using Clang
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC
set_target_properties(unittest PROPERTIES COMPILE_FLAGS "--coverage -fprofile-arcs -ftest-coverage")
target_link_libraries(unittest gcov)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_target_properties(unittest PROPERTIES COMPILE_FLAGS "--coverage -fprofile-arcs -ftest-coverage -Wall -Werror")
target_link_libraries(unittest gcov)
endif()
add_subdirectory(template)
add_subdirectory(img)
#CXXFLAGS="-g -O0 -Wall -W -Wshadow -Wunused-variable \
#Wunused-parameter -Wunused-function -Wunused -Wno-system-headers \
#-Wno-deprecated -Woverloaded-virtual -Wwrite-strings -fprofile-arcs -ftest-coverage"
#CFLAGS="-g -O0 -Wall -W -fprofile-arcs -ftest-coverage"
#LDFLAGS="-fprofile-arcs -ftest-coverage"

17825
tests/catch.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1 @@
cmake_minimum_required(VERSION 2.8)
file(COPY . DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
cmake_minimum_required(VERSION 3.15)

View File

@ -1,29 +1,23 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.15)
project (template_test)
set(PROJECT_INCLUDE_DIR
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/include
)
set(TEST_SRCS
mustachetest.cpp
mustachetest.cpp
)
add_executable(mustachetest ${TEST_SRCS})
#target_link_libraries(unittest crow)
#target_link_libraries(unittest ${Boost_LIBRARIES} )
set_target_properties(mustachetest PROPERTIES COMPILE_FLAGS "-Wall -std=c++1y")
set_target_properties(mustachetest PROPERTIES COMPILE_FLAGS "-Wall -std=c++17")
#message(${PROJECT_SOURCE_DIR})
#message(${CMAKE_CURRENT_BINARY_DIR})
file(COPY DIRECTORY . DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
FILES_MATCHING
PATTERN "*.json")
file(COPY DIRECTORY . DESTINATION ${CMAKE_CURRENT_BINARY_DIR} FILES_MATCHING PATTERN "*.json")
add_custom_command(OUTPUT test.py
COMMAND ${CMAKE_COMMAND} -E
copy ${PROJECT_SOURCE_DIR}/test.py ${CMAKE_CURRENT_BINARY_DIR}/test.py
DEPENDS ${PROJECT_SOURCE_DIR}/test.py
)
)
add_custom_target(template_test_copy ALL DEPENDS test.py)

View File

@ -1,5 +1,5 @@
all:
$(CXX) -Wall -std=c++11 -g -o mustachetest mustachetest.cc
$(CXX) -Wall -std=c++17 -g -o mustachetest mustachetest.cc
.PHONY: clean
clean:
rm -f mustachetest *.o

1
tests/template/README.md Normal file
View File

@ -0,0 +1 @@
Spec json files from https://github.com/mustache/spec

View File

@ -1 +0,0 @@
spec json/yml files from https://github.com/mustache/spec

View File

@ -1 +1 @@
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Comment tags represent content that should never appear in the resulting\noutput.\n\nThe tag's content may contain any substring (including newlines) EXCEPT the\nclosing delimiter.\n\nComment tags SHOULD be treated as standalone when appropriate.\n","tests":[{"name":"Inline","data":{},"expected":"1234567890","template":"12345{{! Comment Block! }}67890","desc":"Comment blocks should be removed from the template."},{"name":"Multiline","data":{},"expected":"1234567890\n","template":"12345{{!\n This is a\n multi-line comment...\n}}67890\n","desc":"Multiline comments should be permitted."},{"name":"Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n{{! Comment Block! }}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Indented Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n {{! Indented Comment Block! }}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n|","template":"|\r\n{{! Standalone Comment }}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags."},{"name":"Standalone Without Previous Line","data":{},"expected":"!","template":" {{! I'm Still Standalone }}\n!","desc":"Standalone tags should not require a newline to precede them."},{"name":"Standalone Without Newline","data":{},"expected":"!\n","template":"!\n {{! I'm Still Standalone }}","desc":"Standalone tags should not require a newline to follow them."},{"name":"Multiline Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n{{!\nSomething's going on here...\n}}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Indented Multiline Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n {{!\n Something's going on here...\n }}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Indented Inline","data":{},"expected":" 12 \n","template":" 12 {{! 34 }}\n","desc":"Inline comments should not strip whitespace"},{"name":"Surrounding Whitespace","data":{},"expected":"12345 67890","template":"12345 {{! Comment Block! }} 67890","desc":"Comment removal should preserve surrounding whitespace."}]}
{"overview":"Comment tags represent content that should never appear in the resulting\noutput.\n\nThe tag's content may contain any substring (including newlines) EXCEPT the\nclosing delimiter.\n\nComment tags SHOULD be treated as standalone when appropriate.\n","tests":[{"name":"Inline","desc":"Comment blocks should be removed from the template.","data":{},"template":"12345{{! Comment Block! }}67890","expected":"1234567890"},{"name":"Multiline","desc":"Multiline comments should be permitted.","data":{},"template":"12345{{!\n This is a\n multi-line comment...\n}}67890\n","expected":"1234567890\n"},{"name":"Standalone","desc":"All standalone comment lines should be removed.","data":{},"template":"Begin.\n{{! Comment Block! }}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Indented Standalone","desc":"All standalone comment lines should be removed.","data":{},"template":"Begin.\n {{! Indented Comment Block! }}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Standalone Line Endings","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","data":{},"template":"|\r\n{{! Standalone Comment }}\r\n|","expected":"|\r\n|"},{"name":"Standalone Without Previous Line","desc":"Standalone tags should not require a newline to precede them.","data":{},"template":" {{! I'm Still Standalone }}\n!","expected":"!"},{"name":"Standalone Without Newline","desc":"Standalone tags should not require a newline to follow them.","data":{},"template":"!\n {{! I'm Still Standalone }}","expected":"!\n"},{"name":"Multiline Standalone","desc":"All standalone comment lines should be removed.","data":{},"template":"Begin.\n{{!\nSomething's going on here...\n}}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Indented Multiline Standalone","desc":"All standalone comment lines should be removed.","data":{},"template":"Begin.\n {{!\n Something's going on here...\n }}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Indented Inline","desc":"Inline comments should not strip whitespace","data":{},"template":" 12 {{! 34 }}\n","expected":" 12 \n"},{"name":"Surrounding Whitespace","desc":"Comment removal should preserve surrounding whitespace.","data":{},"template":"12345 {{! Comment Block! }} 67890","expected":"12345 67890"}],"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file."}

View File

@ -1,103 +0,0 @@
overview: |
Comment tags represent content that should never appear in the resulting
output.
The tag's content may contain any substring (including newlines) EXCEPT the
closing delimiter.
Comment tags SHOULD be treated as standalone when appropriate.
tests:
- name: Inline
desc: Comment blocks should be removed from the template.
data: { }
template: '12345{{! Comment Block! }}67890'
expected: '1234567890'
- name: Multiline
desc: Multiline comments should be permitted.
data: { }
template: |
12345{{!
This is a
multi-line comment...
}}67890
expected: |
1234567890
- name: Standalone
desc: All standalone comment lines should be removed.
data: { }
template: |
Begin.
{{! Comment Block! }}
End.
expected: |
Begin.
End.
- name: Indented Standalone
desc: All standalone comment lines should be removed.
data: { }
template: |
Begin.
{{! Indented Comment Block! }}
End.
expected: |
Begin.
End.
- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { }
template: "|\r\n{{! Standalone Comment }}\r\n|"
expected: "|\r\n|"
- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { }
template: " {{! I'm Still Standalone }}\n!"
expected: "!"
- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { }
template: "!\n {{! I'm Still Standalone }}"
expected: "!\n"
- name: Multiline Standalone
desc: All standalone comment lines should be removed.
data: { }
template: |
Begin.
{{!
Something's going on here...
}}
End.
expected: |
Begin.
End.
- name: Indented Multiline Standalone
desc: All standalone comment lines should be removed.
data: { }
template: |
Begin.
{{!
Something's going on here...
}}
End.
expected: |
Begin.
End.
- name: Indented Inline
desc: Inline comments should not strip whitespace
data: { }
template: " 12 {{! 34 }}\n"
expected: " 12 \n"
- name: Surrounding Whitespace
desc: Comment removal should preserve surrounding whitespace.
data: { }
template: '12345 {{! Comment Block! }} 67890'
expected: '12345 67890'

View File

@ -1 +1 @@
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Set Delimiter tags are used to change the tag delimiters for all content\nfollowing the tag in the current compilation unit.\n\nThe tag's content MUST be any two non-whitespace sequences (separated by\nwhitespace) EXCEPT an equals sign ('=') followed by the current closing\ndelimiter.\n\nSet Delimiter tags SHOULD be treated as standalone when appropriate.\n","tests":[{"name":"Pair Behavior","data":{"text":"Hey!"},"expected":"(Hey!)","template":"{{=<% %>=}}(<%text%>)","desc":"The equals sign (used on both sides) should permit delimiter changes."},{"name":"Special Characters","data":{"text":"It worked!"},"expected":"(It worked!)","template":"({{=[ ]=}}[text])","desc":"Characters with special meaning regexen should be valid delimiters."},{"name":"Sections","data":{"section":true,"data":"I got interpolated."},"expected":"[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n","template":"[\n{{#section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|#section|\n {{data}}\n |data|\n|/section|\n]\n","desc":"Delimiters set outside sections should persist."},{"name":"Inverted Sections","data":{"section":false,"data":"I got interpolated."},"expected":"[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n","template":"[\n{{^section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|^section|\n {{data}}\n |data|\n|/section|\n]\n","desc":"Delimiters set outside inverted sections should persist."},{"name":"Partial Inheritence","data":{"value":"yes"},"expected":"[ .yes. ]\n[ .yes. ]\n","template":"[ {{>include}} ]\n{{= | | =}}\n[ |>include| ]\n","desc":"Delimiters set in a parent template should not affect a partial.","partials":{"include":".{{value}}."}},{"name":"Post-Partial Behavior","data":{"value":"yes"},"expected":"[ .yes. .yes. ]\n[ .yes. .|value|. ]\n","template":"[ {{>include}} ]\n[ .{{value}}. .|value|. ]\n","desc":"Delimiters set in a partial should not affect the parent template.","partials":{"include":".{{value}}. {{= | | =}} .|value|."}},{"name":"Surrounding Whitespace","data":{},"expected":"| |","template":"| {{=@ @=}} |","desc":"Surrounding whitespace should be left untouched."},{"name":"Outlying Whitespace (Inline)","data":{},"expected":" | \n","template":" | {{=@ @=}}\n","desc":"Whitespace should be left untouched."},{"name":"Standalone Tag","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n{{=@ @=}}\nEnd.\n","desc":"Standalone lines should be removed from the template."},{"name":"Indented Standalone Tag","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n {{=@ @=}}\nEnd.\n","desc":"Indented standalone lines should be removed from the template."},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n|","template":"|\r\n{{= @ @ =}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags."},{"name":"Standalone Without Previous Line","data":{},"expected":"=","template":" {{=@ @=}}\n=","desc":"Standalone tags should not require a newline to precede them."},{"name":"Standalone Without Newline","data":{},"expected":"=\n","template":"=\n {{=@ @=}}","desc":"Standalone tags should not require a newline to follow them."},{"name":"Pair with Padding","data":{},"expected":"||","template":"|{{= @ @ =}}|","desc":"Superfluous in-tag whitespace should be ignored."}]}
{"overview":"Set Delimiter tags are used to change the tag delimiters for all content\nfollowing the tag in the current compilation unit.\n\nThe tag's content MUST be any two non-whitespace sequences (separated by\nwhitespace) EXCEPT an equals sign ('=') followed by the current closing\ndelimiter.\n\nSet Delimiter tags SHOULD be treated as standalone when appropriate.\n","tests":[{"name":"Pair Behavior","desc":"The equals sign (used on both sides) should permit delimiter changes.","data":{"text":"Hey!"},"template":"{{=<% %>=}}(<%text%>)","expected":"(Hey!)"},{"name":"Special Characters","desc":"Characters with special meaning regexen should be valid delimiters.","data":{"text":"It worked!"},"template":"({{=[ ]=}}[text])","expected":"(It worked!)"},{"name":"Sections","desc":"Delimiters set outside sections should persist.","data":{"section":true,"data":"I got interpolated."},"template":"[\n{{#section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|#section|\n {{data}}\n |data|\n|/section|\n]\n","expected":"[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n"},{"name":"Inverted Sections","desc":"Delimiters set outside inverted sections should persist.","data":{"section":false,"data":"I got interpolated."},"template":"[\n{{^section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|^section|\n {{data}}\n |data|\n|/section|\n]\n","expected":"[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n"},{"name":"Partial Inheritence","desc":"Delimiters set in a parent template should not affect a partial.","data":{"value":"yes"},"partials":{"include":".{{value}}."},"template":"[ {{>include}} ]\n{{= | | =}}\n[ |>include| ]\n","expected":"[ .yes. ]\n[ .yes. ]\n"},{"name":"Post-Partial Behavior","desc":"Delimiters set in a partial should not affect the parent template.","data":{"value":"yes"},"partials":{"include":".{{value}}. {{= | | =}} .|value|."},"template":"[ {{>include}} ]\n[ .{{value}}. .|value|. ]\n","expected":"[ .yes. .yes. ]\n[ .yes. .|value|. ]\n"},{"name":"Surrounding Whitespace","desc":"Surrounding whitespace should be left untouched.","data":{},"template":"| {{=@ @=}} |","expected":"| |"},{"name":"Outlying Whitespace (Inline)","desc":"Whitespace should be left untouched.","data":{},"template":" | {{=@ @=}}\n","expected":" | \n"},{"name":"Standalone Tag","desc":"Standalone lines should be removed from the template.","data":{},"template":"Begin.\n{{=@ @=}}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Indented Standalone Tag","desc":"Indented standalone lines should be removed from the template.","data":{},"template":"Begin.\n {{=@ @=}}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Standalone Line Endings","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","data":{},"template":"|\r\n{{= @ @ =}}\r\n|","expected":"|\r\n|"},{"name":"Standalone Without Previous Line","desc":"Standalone tags should not require a newline to precede them.","data":{},"template":" {{=@ @=}}\n=","expected":"="},{"name":"Standalone Without Newline","desc":"Standalone tags should not require a newline to follow them.","data":{},"template":"=\n {{=@ @=}}","expected":"=\n"},{"name":"Pair with Padding","desc":"Superfluous in-tag whitespace should be ignored.","data":{},"template":"|{{= @ @ =}}|","expected":"||"}],"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file."}

View File

@ -1,158 +0,0 @@
overview: |
Set Delimiter tags are used to change the tag delimiters for all content
following the tag in the current compilation unit.
The tag's content MUST be any two non-whitespace sequences (separated by
whitespace) EXCEPT an equals sign ('=') followed by the current closing
delimiter.
Set Delimiter tags SHOULD be treated as standalone when appropriate.
tests:
- name: Pair Behavior
desc: The equals sign (used on both sides) should permit delimiter changes.
data: { text: 'Hey!' }
template: '{{=<% %>=}}(<%text%>)'
expected: '(Hey!)'
- name: Special Characters
desc: Characters with special meaning regexen should be valid delimiters.
data: { text: 'It worked!' }
template: '({{=[ ]=}}[text])'
expected: '(It worked!)'
- name: Sections
desc: Delimiters set outside sections should persist.
data: { section: true, data: 'I got interpolated.' }
template: |
[
{{#section}}
{{data}}
|data|
{{/section}}
{{= | | =}}
|#section|
{{data}}
|data|
|/section|
]
expected: |
[
I got interpolated.
|data|
{{data}}
I got interpolated.
]
- name: Inverted Sections
desc: Delimiters set outside inverted sections should persist.
data: { section: false, data: 'I got interpolated.' }
template: |
[
{{^section}}
{{data}}
|data|
{{/section}}
{{= | | =}}
|^section|
{{data}}
|data|
|/section|
]
expected: |
[
I got interpolated.
|data|
{{data}}
I got interpolated.
]
- name: Partial Inheritence
desc: Delimiters set in a parent template should not affect a partial.
data: { value: 'yes' }
partials:
include: '.{{value}}.'
template: |
[ {{>include}} ]
{{= | | =}}
[ |>include| ]
expected: |
[ .yes. ]
[ .yes. ]
- name: Post-Partial Behavior
desc: Delimiters set in a partial should not affect the parent template.
data: { value: 'yes' }
partials:
include: '.{{value}}. {{= | | =}} .|value|.'
template: |
[ {{>include}} ]
[ .{{value}}. .|value|. ]
expected: |
[ .yes. .yes. ]
[ .yes. .|value|. ]
# Whitespace Sensitivity
- name: Surrounding Whitespace
desc: Surrounding whitespace should be left untouched.
data: { }
template: '| {{=@ @=}} |'
expected: '| |'
- name: Outlying Whitespace (Inline)
desc: Whitespace should be left untouched.
data: { }
template: " | {{=@ @=}}\n"
expected: " | \n"
- name: Standalone Tag
desc: Standalone lines should be removed from the template.
data: { }
template: |
Begin.
{{=@ @=}}
End.
expected: |
Begin.
End.
- name: Indented Standalone Tag
desc: Indented standalone lines should be removed from the template.
data: { }
template: |
Begin.
{{=@ @=}}
End.
expected: |
Begin.
End.
- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { }
template: "|\r\n{{= @ @ =}}\r\n|"
expected: "|\r\n|"
- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { }
template: " {{=@ @=}}\n="
expected: "="
- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { }
template: "=\n {{=@ @=}}"
expected: "=\n"
# Whitespace Insensitivity
- name: Pair with Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { }
template: '|{{= @ @ =}}|'
expected: '||'

File diff suppressed because one or more lines are too long

View File

@ -1,238 +0,0 @@
overview: |
Interpolation tags are used to integrate dynamic content into the template.
The tag's content MUST be a non-whitespace character sequence NOT containing
the current closing delimiter.
This tag's content names the data to replace the tag. A single period (`.`)
indicates that the item currently sitting atop the context stack should be
used; otherwise, name resolution is as follows:
1) Split the name on periods; the first part is the name to resolve, any
remaining parts should be retained.
2) Walk the context stack from top to bottom, finding the first context
that is a) a hash containing the name as a key OR b) an object responding
to a method with the given name.
3) If the context is a hash, the data is the value associated with the
name.
4) If the context is an object, the data is the value returned by the
method with the given name.
5) If any name parts were retained in step 1, each should be resolved
against a context stack containing only the result from the former
resolution. If any part fails resolution, the result should be considered
falsey, and should interpolate as the empty string.
Data should be coerced into a string (and escaped, if appropriate) before
interpolation.
The Interpolation tags MUST NOT be treated as standalone.
tests:
- name: No Interpolation
desc: Mustache-free templates should render as-is.
data: { }
template: |
Hello from {Mustache}!
expected: |
Hello from {Mustache}!
- name: Basic Interpolation
desc: Unadorned tags should interpolate content into the template.
data: { subject: "world" }
template: |
Hello, {{subject}}!
expected: |
Hello, world!
- name: HTML Escaping
desc: Basic interpolation should be HTML escaped.
data: { forbidden: '& " < >' }
template: |
These characters should be HTML escaped: {{forbidden}}
expected: |
These characters should be HTML escaped: &amp; &quot; &lt; &gt;
- name: Triple Mustache
desc: Triple mustaches should interpolate without HTML escaping.
data: { forbidden: '& " < >' }
template: |
These characters should not be HTML escaped: {{{forbidden}}}
expected: |
These characters should not be HTML escaped: & " < >
- name: Ampersand
desc: Ampersand should interpolate without HTML escaping.
data: { forbidden: '& " < >' }
template: |
These characters should not be HTML escaped: {{&forbidden}}
expected: |
These characters should not be HTML escaped: & " < >
- name: Basic Integer Interpolation
desc: Integers should interpolate seamlessly.
data: { mph: 85 }
template: '"{{mph}} miles an hour!"'
expected: '"85 miles an hour!"'
- name: Triple Mustache Integer Interpolation
desc: Integers should interpolate seamlessly.
data: { mph: 85 }
template: '"{{{mph}}} miles an hour!"'
expected: '"85 miles an hour!"'
- name: Ampersand Integer Interpolation
desc: Integers should interpolate seamlessly.
data: { mph: 85 }
template: '"{{&mph}} miles an hour!"'
expected: '"85 miles an hour!"'
- name: Basic Decimal Interpolation
desc: Decimals should interpolate seamlessly with proper significance.
data: { power: 1.210 }
template: '"{{power}} jiggawatts!"'
expected: '"1.21 jiggawatts!"'
- name: Triple Mustache Decimal Interpolation
desc: Decimals should interpolate seamlessly with proper significance.
data: { power: 1.210 }
template: '"{{{power}}} jiggawatts!"'
expected: '"1.21 jiggawatts!"'
- name: Ampersand Decimal Interpolation
desc: Decimals should interpolate seamlessly with proper significance.
data: { power: 1.210 }
template: '"{{&power}} jiggawatts!"'
expected: '"1.21 jiggawatts!"'
# Context Misses
- name: Basic Context Miss Interpolation
desc: Failed context lookups should default to empty strings.
data: { }
template: "I ({{cannot}}) be seen!"
expected: "I () be seen!"
- name: Triple Mustache Context Miss Interpolation
desc: Failed context lookups should default to empty strings.
data: { }
template: "I ({{{cannot}}}) be seen!"
expected: "I () be seen!"
- name: Ampersand Context Miss Interpolation
desc: Failed context lookups should default to empty strings.
data: { }
template: "I ({{&cannot}}) be seen!"
expected: "I () be seen!"
# Dotted Names
- name: Dotted Names - Basic Interpolation
desc: Dotted names should be considered a form of shorthand for sections.
data: { person: { name: 'Joe' } }
template: '"{{person.name}}" == "{{#person}}{{name}}{{/person}}"'
expected: '"Joe" == "Joe"'
- name: Dotted Names - Triple Mustache Interpolation
desc: Dotted names should be considered a form of shorthand for sections.
data: { person: { name: 'Joe' } }
template: '"{{{person.name}}}" == "{{#person}}{{{name}}}{{/person}}"'
expected: '"Joe" == "Joe"'
- name: Dotted Names - Ampersand Interpolation
desc: Dotted names should be considered a form of shorthand for sections.
data: { person: { name: 'Joe' } }
template: '"{{&person.name}}" == "{{#person}}{{&name}}{{/person}}"'
expected: '"Joe" == "Joe"'
- name: Dotted Names - Arbitrary Depth
desc: Dotted names should be functional to any level of nesting.
data:
a: { b: { c: { d: { e: { name: 'Phil' } } } } }
template: '"{{a.b.c.d.e.name}}" == "Phil"'
expected: '"Phil" == "Phil"'
- name: Dotted Names - Broken Chains
desc: Any falsey value prior to the last part of the name should yield ''.
data:
a: { }
template: '"{{a.b.c}}" == ""'
expected: '"" == ""'
- name: Dotted Names - Broken Chain Resolution
desc: Each part of a dotted name should resolve only against its parent.
data:
a: { b: { } }
c: { name: 'Jim' }
template: '"{{a.b.c.name}}" == ""'
expected: '"" == ""'
- name: Dotted Names - Initial Resolution
desc: The first part of a dotted name should resolve as any other name.
data:
a: { b: { c: { d: { e: { name: 'Phil' } } } } }
b: { c: { d: { e: { name: 'Wrong' } } } }
template: '"{{#a}}{{b.c.d.e.name}}{{/a}}" == "Phil"'
expected: '"Phil" == "Phil"'
- name: Dotted Names - Context Precedence
desc: Dotted names should be resolved against former resolutions.
data:
a: { b: { } }
b: { c: 'ERROR' }
template: '{{#a}}{{b.c}}{{/a}}'
expected: ''
# Whitespace Sensitivity
- name: Interpolation - Surrounding Whitespace
desc: Interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: '| {{string}} |'
expected: '| --- |'
- name: Triple Mustache - Surrounding Whitespace
desc: Interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: '| {{{string}}} |'
expected: '| --- |'
- name: Ampersand - Surrounding Whitespace
desc: Interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: '| {{&string}} |'
expected: '| --- |'
- name: Interpolation - Standalone
desc: Standalone interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: " {{string}}\n"
expected: " ---\n"
- name: Triple Mustache - Standalone
desc: Standalone interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: " {{{string}}}\n"
expected: " ---\n"
- name: Ampersand - Standalone
desc: Standalone interpolation should not alter surrounding whitespace.
data: { string: '---' }
template: " {{&string}}\n"
expected: " ---\n"
# Whitespace Insensitivity
- name: Interpolation With Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { string: "---" }
template: '|{{ string }}|'
expected: '|---|'
- name: Triple Mustache With Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { string: "---" }
template: '|{{{ string }}}|'
expected: '|---|'
- name: Ampersand With Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { string: "---" }
template: '|{{& string }}|'
expected: '|---|'

File diff suppressed because one or more lines are too long

View File

@ -1,193 +0,0 @@
overview: |
Inverted Section tags and End Section tags are used in combination to wrap a
section of the template.
These tags' content MUST be a non-whitespace character sequence NOT
containing the current closing delimiter; each Inverted Section tag MUST be
followed by an End Section tag with the same content within the same
section.
This tag's content names the data to replace the tag. Name resolution is as
follows:
1) Split the name on periods; the first part is the name to resolve, any
remaining parts should be retained.
2) Walk the context stack from top to bottom, finding the first context
that is a) a hash containing the name as a key OR b) an object responding
to a method with the given name.
3) If the context is a hash, the data is the value associated with the
name.
4) If the context is an object and the method with the given name has an
arity of 1, the method SHOULD be called with a String containing the
unprocessed contents of the sections; the data is the value returned.
5) Otherwise, the data is the value returned by calling the method with
the given name.
6) If any name parts were retained in step 1, each should be resolved
against a context stack containing only the result from the former
resolution. If any part fails resolution, the result should be considered
falsey, and should interpolate as the empty string.
If the data is not of a list type, it is coerced into a list as follows: if
the data is truthy (e.g. `!!data == true`), use a single-element list
containing the data, otherwise use an empty list.
This section MUST NOT be rendered unless the data list is empty.
Inverted Section and End Section tags SHOULD be treated as standalone when
appropriate.
tests:
- name: Falsey
desc: Falsey sections should have their contents rendered.
data: { boolean: false }
template: '"{{^boolean}}This should be rendered.{{/boolean}}"'
expected: '"This should be rendered."'
- name: Truthy
desc: Truthy sections should have their contents omitted.
data: { boolean: true }
template: '"{{^boolean}}This should not be rendered.{{/boolean}}"'
expected: '""'
- name: Context
desc: Objects and hashes should behave like truthy values.
data: { context: { name: 'Joe' } }
template: '"{{^context}}Hi {{name}}.{{/context}}"'
expected: '""'
- name: List
desc: Lists should behave like truthy values.
data: { list: [ { n: 1 }, { n: 2 }, { n: 3 } ] }
template: '"{{^list}}{{n}}{{/list}}"'
expected: '""'
- name: Empty List
desc: Empty lists should behave like falsey values.
data: { list: [ ] }
template: '"{{^list}}Yay lists!{{/list}}"'
expected: '"Yay lists!"'
- name: Doubled
desc: Multiple inverted sections per template should be permitted.
data: { bool: false, two: 'second' }
template: |
{{^bool}}
* first
{{/bool}}
* {{two}}
{{^bool}}
* third
{{/bool}}
expected: |
* first
* second
* third
- name: Nested (Falsey)
desc: Nested falsey sections should have their contents rendered.
data: { bool: false }
template: "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |"
expected: "| A B C D E |"
- name: Nested (Truthy)
desc: Nested truthy sections should be omitted.
data: { bool: true }
template: "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |"
expected: "| A E |"
- name: Context Misses
desc: Failed context lookups should be considered falsey.
data: { }
template: "[{{^missing}}Cannot find key 'missing'!{{/missing}}]"
expected: "[Cannot find key 'missing'!]"
# Dotted Names
- name: Dotted Names - Truthy
desc: Dotted names should be valid for Inverted Section tags.
data: { a: { b: { c: true } } }
template: '"{{^a.b.c}}Not Here{{/a.b.c}}" == ""'
expected: '"" == ""'
- name: Dotted Names - Falsey
desc: Dotted names should be valid for Inverted Section tags.
data: { a: { b: { c: false } } }
template: '"{{^a.b.c}}Not Here{{/a.b.c}}" == "Not Here"'
expected: '"Not Here" == "Not Here"'
- name: Dotted Names - Broken Chains
desc: Dotted names that cannot be resolved should be considered falsey.
data: { a: { } }
template: '"{{^a.b.c}}Not Here{{/a.b.c}}" == "Not Here"'
expected: '"Not Here" == "Not Here"'
# Whitespace Sensitivity
- name: Surrounding Whitespace
desc: Inverted sections should not alter surrounding whitespace.
data: { boolean: false }
template: " | {{^boolean}}\t|\t{{/boolean}} | \n"
expected: " | \t|\t | \n"
- name: Internal Whitespace
desc: Inverted should not alter internal whitespace.
data: { boolean: false }
template: " | {{^boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n"
expected: " | \n | \n"
- name: Indented Inline Sections
desc: Single-line sections should not alter surrounding whitespace.
data: { boolean: false }
template: " {{^boolean}}NO{{/boolean}}\n {{^boolean}}WAY{{/boolean}}\n"
expected: " NO\n WAY\n"
- name: Standalone Lines
desc: Standalone lines should be removed from the template.
data: { boolean: false }
template: |
| This Is
{{^boolean}}
|
{{/boolean}}
| A Line
expected: |
| This Is
|
| A Line
- name: Standalone Indented Lines
desc: Standalone indented lines should be removed from the template.
data: { boolean: false }
template: |
| This Is
{{^boolean}}
|
{{/boolean}}
| A Line
expected: |
| This Is
|
| A Line
- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { boolean: false }
template: "|\r\n{{^boolean}}\r\n{{/boolean}}\r\n|"
expected: "|\r\n|"
- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { boolean: false }
template: " {{^boolean}}\n^{{/boolean}}\n/"
expected: "^\n/"
- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { boolean: false }
template: "^{{^boolean}}\n/\n {{/boolean}}"
expected: "^\n/\n"
# Whitespace Insensitivity
- name: Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { boolean: false }
template: '|{{^ boolean }}={{/ boolean }}|'
expected: '|=|'

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Partial tags are used to expand an external template into the current\ntemplate.\n\nThe tag's content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter.\n\nThis tag's content names the partial to inject. Set Delimiter tags MUST NOT\naffect the parsing of a partial. The partial MUST be rendered against the\ncontext stack local to the tag. If the named partial cannot be found, the\nempty string SHOULD be used instead, as in interpolations.\n\nPartial tags SHOULD be treated as standalone when appropriate. If this tag\nis used standalone, any whitespace preceding the tag should treated as\nindentation, and prepended to each line of the partial before rendering.\n","tests":[{"name":"Basic Behavior","data":{},"expected":"\"from partial\"","template":"\"{{>text}}\"","desc":"The greater-than operator should expand to the named partial.","partials":{"text":"from partial"}},{"name":"Failed Lookup","data":{},"expected":"\"\"","template":"\"{{>text}}\"","desc":"The empty string should be used when the named partial is not found.","partials":{}},{"name":"Context","data":{"text":"content"},"expected":"\"*content*\"","template":"\"{{>partial}}\"","desc":"The greater-than operator should operate within the current context.","partials":{"partial":"*{{text}}*"}},{"name":"Recursion","data":{"content":"X","nodes":[{"content":"Y","nodes":[]}]},"expected":"X<Y<>>","template":"{{>node}}","desc":"The greater-than operator should properly recurse.","partials":{"node":"{{content}}<{{#nodes}}{{>node}}{{/nodes}}>"}},{"name":"Surrounding Whitespace","data":{},"expected":"| \t|\t |","template":"| {{>partial}} |","desc":"The greater-than operator should not alter surrounding whitespace.","partials":{"partial":"\t|\t"}},{"name":"Inline Indentation","data":{"data":"|"},"expected":" | >\n>\n","template":" {{data}} {{> partial}}\n","desc":"Whitespace should be left untouched.","partials":{"partial":">\n>"}},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n>|","template":"|\r\n{{>partial}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","partials":{"partial":">"}},{"name":"Standalone Without Previous Line","data":{},"expected":" >\n >>","template":" {{>partial}}\n>","desc":"Standalone tags should not require a newline to precede them.","partials":{"partial":">\n>"}},{"name":"Standalone Without Newline","data":{},"expected":">\n >\n >","template":">\n {{>partial}}","desc":"Standalone tags should not require a newline to follow them.","partials":{"partial":">\n>"}},{"name":"Standalone Indentation","data":{"content":"<\n->"},"expected":"\\\n |\n <\n->\n |\n/\n","template":"\\\n {{>partial}}\n/\n","desc":"Each line of the partial should be indented before rendering.","partials":{"partial":"|\n{{{content}}}\n|\n"}},{"name":"Padding Whitespace","data":{"boolean":true},"expected":"|[]|","template":"|{{> partial }}|","desc":"Superfluous in-tag whitespace should be ignored.","partials":{"partial":"[]"}}]}
{"overview":"Partial tags are used to expand an external template into the current\ntemplate.\n\nThe tag's content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter.\n\nThis tag's content names the partial to inject. Set Delimiter tags MUST NOT\naffect the parsing of a partial. The partial MUST be rendered against the\ncontext stack local to the tag. If the named partial cannot be found, the\nempty string SHOULD be used instead, as in interpolations.\n\nPartial tags SHOULD be treated as standalone when appropriate. If this tag\nis used standalone, any whitespace preceding the tag should treated as\nindentation, and prepended to each line of the partial before rendering.\n","tests":[{"name":"Basic Behavior","desc":"The greater-than operator should expand to the named partial.","data":{},"template":"\"{{>text}}\"","partials":{"text":"from partial"},"expected":"\"from partial\""},{"name":"Failed Lookup","desc":"The empty string should be used when the named partial is not found.","data":{},"template":"\"{{>text}}\"","partials":{},"expected":"\"\""},{"name":"Context","desc":"The greater-than operator should operate within the current context.","data":{"text":"content"},"template":"\"{{>partial}}\"","partials":{"partial":"*{{text}}*"},"expected":"\"*content*\""},{"name":"Recursion","desc":"The greater-than operator should properly recurse.","data":{"content":"X","nodes":[{"content":"Y","nodes":[]}]},"template":"{{>node}}","partials":{"node":"{{content}}<{{#nodes}}{{>node}}{{/nodes}}>"},"expected":"X<Y<>>"},{"name":"Surrounding Whitespace","desc":"The greater-than operator should not alter surrounding whitespace.","data":{},"template":"| {{>partial}} |","partials":{"partial":"\t|\t"},"expected":"| \t|\t |"},{"name":"Inline Indentation","desc":"Whitespace should be left untouched.","data":{"data":"|"},"template":" {{data}} {{> partial}}\n","partials":{"partial":">\n>"},"expected":" | >\n>\n"},{"name":"Standalone Line Endings","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","data":{},"template":"|\r\n{{>partial}}\r\n|","partials":{"partial":">"},"expected":"|\r\n>|"},{"name":"Standalone Without Previous Line","desc":"Standalone tags should not require a newline to precede them.","data":{},"template":" {{>partial}}\n>","partials":{"partial":">\n>"},"expected":" >\n >>"},{"name":"Standalone Without Newline","desc":"Standalone tags should not require a newline to follow them.","data":{},"template":">\n {{>partial}}","partials":{"partial":">\n>"},"expected":">\n >\n >"},{"name":"Standalone Indentation","desc":"Each line of the partial should be indented before rendering.","data":{"content":"<\n->"},"template":"\\\n {{>partial}}\n/\n","partials":{"partial":"|\n{{{content}}}\n|\n"},"expected":"\\\n |\n <\n->\n |\n/\n"},{"name":"Padding Whitespace","desc":"Superfluous in-tag whitespace should be ignored.","data":{"boolean":true},"template":"|{{> partial }}|","partials":{"partial":"[]"},"expected":"|[]|"}],"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file."}

View File

@ -1,109 +0,0 @@
overview: |
Partial tags are used to expand an external template into the current
template.
The tag's content MUST be a non-whitespace character sequence NOT containing
the current closing delimiter.
This tag's content names the partial to inject. Set Delimiter tags MUST NOT
affect the parsing of a partial. The partial MUST be rendered against the
context stack local to the tag. If the named partial cannot be found, the
empty string SHOULD be used instead, as in interpolations.
Partial tags SHOULD be treated as standalone when appropriate. If this tag
is used standalone, any whitespace preceding the tag should treated as
indentation, and prepended to each line of the partial before rendering.
tests:
- name: Basic Behavior
desc: The greater-than operator should expand to the named partial.
data: { }
template: '"{{>text}}"'
partials: { text: 'from partial' }
expected: '"from partial"'
- name: Failed Lookup
desc: The empty string should be used when the named partial is not found.
data: { }
template: '"{{>text}}"'
partials: { }
expected: '""'
- name: Context
desc: The greater-than operator should operate within the current context.
data: { text: 'content' }
template: '"{{>partial}}"'
partials: { partial: '*{{text}}*' }
expected: '"*content*"'
- name: Recursion
desc: The greater-than operator should properly recurse.
data: { content: "X", nodes: [ { content: "Y", nodes: [] } ] }
template: '{{>node}}'
partials: { node: '{{content}}<{{#nodes}}{{>node}}{{/nodes}}>' }
expected: 'X<Y<>>'
# Whitespace Sensitivity
- name: Surrounding Whitespace
desc: The greater-than operator should not alter surrounding whitespace.
data: { }
template: '| {{>partial}} |'
partials: { partial: "\t|\t" }
expected: "| \t|\t |"
- name: Inline Indentation
desc: Whitespace should be left untouched.
data: { data: '|' }
template: " {{data}} {{> partial}}\n"
partials: { partial: ">\n>" }
expected: " | >\n>\n"
- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { }
template: "|\r\n{{>partial}}\r\n|"
partials: { partial: ">" }
expected: "|\r\n>|"
- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { }
template: " {{>partial}}\n>"
partials: { partial: ">\n>"}
expected: " >\n >>"
- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { }
template: ">\n {{>partial}}"
partials: { partial: ">\n>" }
expected: ">\n >\n >"
- name: Standalone Indentation
desc: Each line of the partial should be indented before rendering.
data: { content: "<\n->" }
template: |
\
{{>partial}}
/
partials:
partial: |
|
{{{content}}}
|
expected: |
\
|
<
->
|
/
# Whitespace Insensitivity
- name: Padding Whitespace
desc: Superfluous in-tag whitespace should be ignored.
data: { boolean: true }
template: "|{{> partial }}|"
partials: { partial: "[]" }
expected: '|[]|'

File diff suppressed because one or more lines are too long

View File

@ -1,256 +0,0 @@
overview: |
Section tags and End Section tags are used in combination to wrap a section
of the template for iteration
These tags' content MUST be a non-whitespace character sequence NOT
containing the current closing delimiter; each Section tag MUST be followed
by an End Section tag with the same content within the same section.
This tag's content names the data to replace the tag. Name resolution is as
follows:
1) Split the name on periods; the first part is the name to resolve, any
remaining parts should be retained.
2) Walk the context stack from top to bottom, finding the first context
that is a) a hash containing the name as a key OR b) an object responding
to a method with the given name.
3) If the context is a hash, the data is the value associated with the
name.
4) If the context is an object and the method with the given name has an
arity of 1, the method SHOULD be called with a String containing the
unprocessed contents of the sections; the data is the value returned.
5) Otherwise, the data is the value returned by calling the method with
the given name.
6) If any name parts were retained in step 1, each should be resolved
against a context stack containing only the result from the former
resolution. If any part fails resolution, the result should be considered
falsey, and should interpolate as the empty string.
If the data is not of a list type, it is coerced into a list as follows: if
the data is truthy (e.g. `!!data == true`), use a single-element list
containing the data, otherwise use an empty list.
For each element in the data list, the element MUST be pushed onto the
context stack, the section MUST be rendered, and the element MUST be popped
off the context stack.
Section and End Section tags SHOULD be treated as standalone when
appropriate.
tests:
- name: Truthy
desc: Truthy sections should have their contents rendered.
data: { boolean: true }
template: '"{{#boolean}}This should be rendered.{{/boolean}}"'
expected: '"This should be rendered."'
- name: Falsey
desc: Falsey sections should have their contents omitted.
data: { boolean: false }
template: '"{{#boolean}}This should not be rendered.{{/boolean}}"'
expected: '""'
- name: Context
desc: Objects and hashes should be pushed onto the context stack.
data: { context: { name: 'Joe' } }
template: '"{{#context}}Hi {{name}}.{{/context}}"'
expected: '"Hi Joe."'
- name: Deeply Nested Contexts
desc: All elements on the context stack should be accessible.
data:
a: { one: 1 }
b: { two: 2 }
c: { three: 3 }
d: { four: 4 }
e: { five: 5 }
template: |
{{#a}}
{{one}}
{{#b}}
{{one}}{{two}}{{one}}
{{#c}}
{{one}}{{two}}{{three}}{{two}}{{one}}
{{#d}}
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
{{#e}}
{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}
{{/e}}
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
{{/d}}
{{one}}{{two}}{{three}}{{two}}{{one}}
{{/c}}
{{one}}{{two}}{{one}}
{{/b}}
{{one}}
{{/a}}
expected: |
1
121
12321
1234321
123454321
1234321
12321
121
1
- name: List
desc: Lists should be iterated; list items should visit the context stack.
data: { list: [ { item: 1 }, { item: 2 }, { item: 3 } ] }
template: '"{{#list}}{{item}}{{/list}}"'
expected: '"123"'
- name: Empty List
desc: Empty lists should behave like falsey values.
data: { list: [ ] }
template: '"{{#list}}Yay lists!{{/list}}"'
expected: '""'
- name: Doubled
desc: Multiple sections per template should be permitted.
data: { bool: true, two: 'second' }
template: |
{{#bool}}
* first
{{/bool}}
* {{two}}
{{#bool}}
* third
{{/bool}}
expected: |
* first
* second
* third
- name: Nested (Truthy)
desc: Nested truthy sections should have their contents rendered.
data: { bool: true }
template: "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |"
expected: "| A B C D E |"
- name: Nested (Falsey)
desc: Nested falsey sections should be omitted.
data: { bool: false }
template: "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |"
expected: "| A E |"
- name: Context Misses
desc: Failed context lookups should be considered falsey.
data: { }
template: "[{{#missing}}Found key 'missing'!{{/missing}}]"
expected: "[]"
# Implicit Iterators
- name: Implicit Iterator - String
desc: Implicit iterators should directly interpolate strings.
data:
list: [ 'a', 'b', 'c', 'd', 'e' ]
template: '"{{#list}}({{.}}){{/list}}"'
expected: '"(a)(b)(c)(d)(e)"'
- name: Implicit Iterator - Integer
desc: Implicit iterators should cast integers to strings and interpolate.
data:
list: [ 1, 2, 3, 4, 5 ]
template: '"{{#list}}({{.}}){{/list}}"'
expected: '"(1)(2)(3)(4)(5)"'
- name: Implicit Iterator - Decimal
desc: Implicit iterators should cast decimals to strings and interpolate.
data:
list: [ 1.10, 2.20, 3.30, 4.40, 5.50 ]
template: '"{{#list}}({{.}}){{/list}}"'
expected: '"(1.1)(2.2)(3.3)(4.4)(5.5)"'
# Dotted Names
- name: Dotted Names - Truthy
desc: Dotted names should be valid for Section tags.
data: { a: { b: { c: true } } }
template: '"{{#a.b.c}}Here{{/a.b.c}}" == "Here"'
expected: '"Here" == "Here"'
- name: Dotted Names - Falsey
desc: Dotted names should be valid for Section tags.
data: { a: { b: { c: false } } }
template: '"{{#a.b.c}}Here{{/a.b.c}}" == ""'
expected: '"" == ""'
- name: Dotted Names - Broken Chains
desc: Dotted names that cannot be resolved should be considered falsey.
data: { a: { } }
template: '"{{#a.b.c}}Here{{/a.b.c}}" == ""'
expected: '"" == ""'
# Whitespace Sensitivity
- name: Surrounding Whitespace
desc: Sections should not alter surrounding whitespace.
data: { boolean: true }
template: " | {{#boolean}}\t|\t{{/boolean}} | \n"
expected: " | \t|\t | \n"
- name: Internal Whitespace
desc: Sections should not alter internal whitespace.
data: { boolean: true }
template: " | {{#boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n"
expected: " | \n | \n"
- name: Indented Inline Sections
desc: Single-line sections should not alter surrounding whitespace.
data: { boolean: true }
template: " {{#boolean}}YES{{/boolean}}\n {{#boolean}}GOOD{{/boolean}}\n"
expected: " YES\n GOOD\n"
- name: Standalone Lines
desc: Standalone lines should be removed from the template.
data: { boolean: true }
template: |
| This Is
{{#boolean}}
|
{{/boolean}}
| A Line
expected: |
| This Is
|
| A Line
- name: Indented Standalone Lines
desc: Indented standalone lines should be removed from the template.
data: { boolean: true }
template: |
| This Is
{{#boolean}}
|
{{/boolean}}
| A Line
expected: |
| This Is
|
| A Line
- name: Standalone Line Endings
desc: '"\r\n" should be considered a newline for standalone tags.'
data: { boolean: true }
template: "|\r\n{{#boolean}}\r\n{{/boolean}}\r\n|"
expected: "|\r\n|"
- name: Standalone Without Previous Line
desc: Standalone tags should not require a newline to precede them.
data: { boolean: true }
template: " {{#boolean}}\n#{{/boolean}}\n/"
expected: "#\n/"
- name: Standalone Without Newline
desc: Standalone tags should not require a newline to follow them.
data: { boolean: true }
template: "#{{#boolean}}\n/\n {{/boolean}}"
expected: "#\n/\n"
# Whitespace Insensitivity
- name: Padding
desc: Superfluous in-tag whitespace should be ignored.
data: { boolean: true }
template: '|{{# boolean }}={{/ boolean }}|'
expected: '|=|'

File diff suppressed because one or more lines are too long

View File

@ -1,149 +0,0 @@
overview: |
Lambdas are a special-cased data type for use in interpolations and
sections.
When used as the data value for an Interpolation tag, the lambda MUST be
treatable as an arity 0 function, and invoked as such. The returned value
MUST be rendered against the default delimiters, then interpolated in place
of the lambda.
When used as the data value for a Section tag, the lambda MUST be treatable
as an arity 1 function, and invoked as such (passing a String containing the
unprocessed section contents). The returned value MUST be rendered against
the current delimiters, then interpolated in place of the section.
tests:
- name: Interpolation
desc: A lambda's return value should be interpolated.
data:
lambda: !code
ruby: 'proc { "world" }'
perl: 'sub { "world" }'
js: 'function() { return "world" }'
php: 'return "world";'
python: 'lambda: "world"'
clojure: '(fn [] "world")'
template: "Hello, {{lambda}}!"
expected: "Hello, world!"
- name: Interpolation - Expansion
desc: A lambda's return value should be parsed.
data:
planet: "world"
lambda: !code
ruby: 'proc { "{{planet}}" }'
perl: 'sub { "{{planet}}" }'
js: 'function() { return "{{planet}}" }'
php: 'return "{{planet}}";'
python: 'lambda: "{{planet}}"'
clojure: '(fn [] "{{planet}}")'
template: "Hello, {{lambda}}!"
expected: "Hello, world!"
- name: Interpolation - Alternate Delimiters
desc: A lambda's return value should parse with the default delimiters.
data:
planet: "world"
lambda: !code
ruby: 'proc { "|planet| => {{planet}}" }'
perl: 'sub { "|planet| => {{planet}}" }'
js: 'function() { return "|planet| => {{planet}}" }'
php: 'return "|planet| => {{planet}}";'
python: 'lambda: "|planet| => {{planet}}"'
clojure: '(fn [] "|planet| => {{planet}}")'
template: "{{= | | =}}\nHello, (|&lambda|)!"
expected: "Hello, (|planet| => world)!"
- name: Interpolation - Multiple Calls
desc: Interpolated lambdas should not be cached.
data:
lambda: !code
ruby: 'proc { $calls ||= 0; $calls += 1 }'
perl: 'sub { no strict; $calls += 1 }'
js: 'function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }'
php: 'global $calls; return ++$calls;'
python: 'lambda: globals().update(calls=globals().get("calls",0)+1) or calls'
clojure: '(def g (atom 0)) (fn [] (swap! g inc))'
template: '{{lambda}} == {{{lambda}}} == {{lambda}}'
expected: '1 == 2 == 3'
- name: Escaping
desc: Lambda results should be appropriately escaped.
data:
lambda: !code
ruby: 'proc { ">" }'
perl: 'sub { ">" }'
js: 'function() { return ">" }'
php: 'return ">";'
python: 'lambda: ">"'
clojure: '(fn [] ">")'
template: "<{{lambda}}{{{lambda}}}"
expected: "<&gt;>"
- name: Section
desc: Lambdas used for sections should receive the raw section string.
data:
x: 'Error!'
lambda: !code
ruby: 'proc { |text| text == "{{x}}" ? "yes" : "no" }'
perl: 'sub { $_[0] eq "{{x}}" ? "yes" : "no" }'
js: 'function(txt) { return (txt == "{{x}}" ? "yes" : "no") }'
php: 'return ($text == "{{x}}") ? "yes" : "no";'
python: 'lambda text: text == "{{x}}" and "yes" or "no"'
clojure: '(fn [text] (if (= text "{{x}}") "yes" "no"))'
template: "<{{#lambda}}{{x}}{{/lambda}}>"
expected: "<yes>"
- name: Section - Expansion
desc: Lambdas used for sections should have their results parsed.
data:
planet: "Earth"
lambda: !code
ruby: 'proc { |text| "#{text}{{planet}}#{text}" }'
perl: 'sub { $_[0] . "{{planet}}" . $_[0] }'
js: 'function(txt) { return txt + "{{planet}}" + txt }'
php: 'return $text . "{{planet}}" . $text;'
python: 'lambda text: "%s{{planet}}%s" % (text, text)'
clojure: '(fn [text] (str text "{{planet}}" text))'
template: "<{{#lambda}}-{{/lambda}}>"
expected: "<-Earth->"
- name: Section - Alternate Delimiters
desc: Lambdas used for sections should parse with the current delimiters.
data:
planet: "Earth"
lambda: !code
ruby: 'proc { |text| "#{text}{{planet}} => |planet|#{text}" }'
perl: 'sub { $_[0] . "{{planet}} => |planet|" . $_[0] }'
js: 'function(txt) { return txt + "{{planet}} => |planet|" + txt }'
php: 'return $text . "{{planet}} => |planet|" . $text;'
python: 'lambda text: "%s{{planet}} => |planet|%s" % (text, text)'
clojure: '(fn [text] (str text "{{planet}} => |planet|" text))'
template: "{{= | | =}}<|#lambda|-|/lambda|>"
expected: "<-{{planet}} => Earth->"
- name: Section - Multiple Calls
desc: Lambdas used for sections should not be cached.
data:
lambda: !code
ruby: 'proc { |text| "__#{text}__" }'
perl: 'sub { "__" . $_[0] . "__" }'
js: 'function(txt) { return "__" + txt + "__" }'
php: 'return "__" . $text . "__";'
python: 'lambda text: "__%s__" % (text)'
clojure: '(fn [text] (str "__" text "__"))'
template: '{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}'
expected: '__FILE__ != __LINE__'
- name: Inverted Section
desc: Lambdas used for inverted sections should be considered truthy.
data:
static: 'static'
lambda: !code
ruby: 'proc { |text| false }'
perl: 'sub { 0 }'
js: 'function(txt) { return false }'
php: 'return false;'
python: 'lambda text: 0'
clojure: '(fn [text] false)'
template: "<{{^lambda}}{{static}}{{/lambda}}>"
expected: "<>"

View File

@ -1,59 +1,18 @@
//#define CROW_ENABLE_LOGGING
#define CROW_LOG_LEVEL 0
#define CROW_ENABLE_DEBUG
#define CATCH_CONFIG_MAIN
#define CROW_LOG_LEVEL 10
#include <iostream>
#include <sstream>
#include <vector>
#include <sys/stat.h>
#include "crow.h"
#include "catch.hpp"
using namespace std;
using namespace crow;
struct Test { Test(); virtual void test() = 0; };
vector<Test*> tests;
Test::Test() { tests.push_back(this); }
bool failed__ = false;
void error_print()
{
cerr << endl;
}
template <typename A, typename ...Args>
void error_print(const A& a, Args...args)
{
cerr<<a;
error_print(args...);
}
template <typename ...Args>
void fail(Args...args) { error_print(args...);failed__ = true; }
#define ASSERT_TRUE(x) if (!(x)) fail(__FILE__ ":", __LINE__, ": Assert fail: expected ", #x, " is true, at " __FILE__ ":",__LINE__)
#define ASSERT_EQUAL(a, b) if ((a) != (b)) fail(__FILE__ ":", __LINE__, ": Assert fail: expected ", (a), " actual ", (b), ", " #a " == " #b ", at " __FILE__ ":",__LINE__)
#define ASSERT_NOTEQUAL(a, b) if ((a) == (b)) fail(__FILE__ ":", __LINE__, ": Assert fail: not expected ", (a), ", " #a " != " #b ", at " __FILE__ ":",__LINE__)
#define ASSERT_THROW(x) \
try \
{ \
x; \
fail(__FILE__ ":", __LINE__, ": Assert fail: exception should be thrown"); \
} \
catch(std::exception&) \
{ \
}
#define TEST(x) struct test##x:public Test{void test();}x##_; \
void test##x::test()
#define DISABLE_TEST(x) struct test##x{void test();}x##_; \
void test##x::test()
#define LOCALHOST_ADDRESS "127.0.0.1"
TEST(Rule)
TEST_CASE("Rule")
{
TaggedRule<> r("/http/");
r.name("abc");
@ -62,7 +21,7 @@ TEST(Rule)
try
{
r.validate();
fail("empty handler should fail to validate");
FAIL_CHECK("empty handler should fail to validate");
}
catch(runtime_error& e)
{
@ -78,9 +37,9 @@ TEST(Rule)
response res;
// executing handler
ASSERT_EQUAL(0, x);
REQUIRE(0 == x);
r.handle(request(), res, routing_params());
ASSERT_EQUAL(1, x);
REQUIRE(1 == x);
// registering handler with request argument
r([&x](const crow::request&){x = 2;return "";});
@ -88,32 +47,32 @@ TEST(Rule)
r.validate();
// executing handler
ASSERT_EQUAL(1, x);
REQUIRE(1 == x);
r.handle(request(), res, routing_params());
ASSERT_EQUAL(2, x);
REQUIRE(2 == x);
}
TEST(ParameterTagging)
TEST_CASE("ParameterTagging")
{
static_assert(black_magic::is_valid("<int><int><int>"), "valid url");
static_assert(!black_magic::is_valid("<int><int<<int>"), "invalid url");
static_assert(!black_magic::is_valid("nt>"), "invalid url");
ASSERT_EQUAL(1, black_magic::get_parameter_tag("<int>"));
ASSERT_EQUAL(2, black_magic::get_parameter_tag("<uint>"));
ASSERT_EQUAL(3, black_magic::get_parameter_tag("<float>"));
ASSERT_EQUAL(3, black_magic::get_parameter_tag("<double>"));
ASSERT_EQUAL(4, black_magic::get_parameter_tag("<str>"));
ASSERT_EQUAL(4, black_magic::get_parameter_tag("<string>"));
ASSERT_EQUAL(5, black_magic::get_parameter_tag("<path>"));
ASSERT_EQUAL(6*6+6+1, black_magic::get_parameter_tag("<int><int><int>"));
ASSERT_EQUAL(6*6+6+2, black_magic::get_parameter_tag("<uint><int><int>"));
ASSERT_EQUAL(6*6+6*3+2, black_magic::get_parameter_tag("<uint><double><int>"));
REQUIRE(1 == black_magic::get_parameter_tag("<int>"));
REQUIRE(2 == black_magic::get_parameter_tag("<uint>"));
REQUIRE(3 == black_magic::get_parameter_tag("<float>"));
REQUIRE(3 == black_magic::get_parameter_tag("<double>"));
REQUIRE(4 == black_magic::get_parameter_tag("<str>"));
REQUIRE(4 == black_magic::get_parameter_tag("<string>"));
REQUIRE(5 == black_magic::get_parameter_tag("<path>"));
REQUIRE(6*6+6+1 == black_magic::get_parameter_tag("<int><int><int>"));
REQUIRE(6*6+6+2 == black_magic::get_parameter_tag("<uint><int><int>"));
REQUIRE(6*6+6*3+2 == black_magic::get_parameter_tag("<uint><double><int>"));
// url definition parsed in compile time, build into *one number*, and given to template argument
static_assert(std::is_same<black_magic::S<uint64_t, double, int64_t>, black_magic::arguments<6*6+6*3+2>::type>::value, "tag to type container");
}
TEST(PathRouting)
TEST_CASE("PathRouting")
{
SimpleApp app;
@ -137,7 +96,7 @@ TEST(PathRouting)
app.handle(req, res);
ASSERT_EQUAL(200, res.code);
REQUIRE(200 == res.code);
}
{
request req;
@ -146,7 +105,7 @@ TEST(PathRouting)
req.url = "/file/";
app.handle(req, res);
ASSERT_EQUAL(404, res.code);
REQUIRE(404 == res.code);
}
{
request req;
@ -155,7 +114,7 @@ TEST(PathRouting)
req.url = "/path";
app.handle(req, res);
ASSERT_NOTEQUAL(404, res.code);
REQUIRE(404 != res.code);
}
{
request req;
@ -164,11 +123,11 @@ TEST(PathRouting)
req.url = "/path/";
app.handle(req, res);
ASSERT_EQUAL(200, res.code);
REQUIRE(200 == res.code);
}
}
TEST(RoutingTest)
TEST_CASE("RoutingTest")
{
SimpleApp app;
int A{};
@ -211,7 +170,7 @@ TEST(RoutingTest)
app.handle(req, res);
ASSERT_EQUAL(404, res.code);
REQUIRE(404 == res.code);
}
{
@ -222,9 +181,9 @@ TEST(RoutingTest)
app.handle(req, res);
ASSERT_EQUAL(200, res.code);
REQUIRE(200 == res.code);
ASSERT_EQUAL(1001999, B);
REQUIRE(1001999 == B);
}
{
@ -235,10 +194,10 @@ TEST(RoutingTest)
app.handle(req, res);
ASSERT_EQUAL(200, res.code);
REQUIRE(200 == res.code);
ASSERT_EQUAL(-100, A);
ASSERT_EQUAL(1999, B);
REQUIRE(-100 == A);
REQUIRE(1999 == B);
}
{
request req;
@ -249,12 +208,12 @@ TEST(RoutingTest)
app.handle(req, res);
ASSERT_EQUAL(200, res.code);
REQUIRE(200 == res.code);
ASSERT_EQUAL(5000, A);
ASSERT_EQUAL(3, B);
ASSERT_EQUAL(-2.71828, C);
ASSERT_EQUAL("hellhere", D);
REQUIRE(5000 == A);
REQUIRE(3 == B);
REQUIRE(-2.71828 == C);
REQUIRE("hellhere" == D);
}
{
request req;
@ -265,21 +224,21 @@ TEST(RoutingTest)
app.handle(req, res);
ASSERT_EQUAL(200, res.code);
REQUIRE(200 == res.code);
ASSERT_EQUAL(-5, A);
ASSERT_EQUAL(999, B);
ASSERT_EQUAL(3.141592, C);
ASSERT_EQUAL("hello_there", D);
ASSERT_EQUAL("a/b/c/d", E);
REQUIRE(-5 == A);
REQUIRE(999 == B);
REQUIRE(3.141592 == C);
REQUIRE("hello_there" == D);
REQUIRE("a/b/c/d" == E);
}
}
TEST(simple_response_routing_params)
TEST_CASE("simple_response_routing_params")
{
ASSERT_EQUAL(100, response(100).code);
ASSERT_EQUAL(200, response("Hello there").code);
ASSERT_EQUAL(500, response(500, "Internal Error?").code);
REQUIRE(100 == response(100).code);
REQUIRE(200 == response("Hello there").code);
REQUIRE(500 == response(500, "Internal Error?").code);
routing_params rp;
rp.int_params.push_back(1);
@ -287,14 +246,14 @@ TEST(simple_response_routing_params)
rp.uint_params.push_back(2);
rp.double_params.push_back(3);
rp.string_params.push_back("hello");
ASSERT_EQUAL(1, rp.get<int64_t>(0));
ASSERT_EQUAL(5, rp.get<int64_t>(1));
ASSERT_EQUAL(2, rp.get<uint64_t>(0));
ASSERT_EQUAL(3, rp.get<double>(0));
ASSERT_EQUAL("hello", rp.get<string>(0));
REQUIRE(1 == rp.get<int64_t>(0));
REQUIRE(5 == rp.get<int64_t>(1));
REQUIRE(2 == rp.get<uint64_t>(0));
REQUIRE(3 == rp.get<double>(0));
REQUIRE("hello" == rp.get<string>(0));
}
TEST(handler_with_response)
TEST_CASE("handler_with_response")
{
SimpleApp app;
CROW_ROUTE(app, "/")([](const crow::request&, crow::response&)
@ -302,7 +261,7 @@ TEST(handler_with_response)
});
}
TEST(http_method)
TEST_CASE("http_method")
{
SimpleApp app;
@ -352,7 +311,7 @@ TEST(http_method)
req.url = "/";
app.handle(req, res);
ASSERT_EQUAL("2", res.body);
REQUIRE("2" == res.body);
}
{
request req;
@ -362,7 +321,7 @@ TEST(http_method)
req.method = "POST"_method;
app.handle(req, res);
ASSERT_EQUAL("1", res.body);
REQUIRE("1" == res.body);
}
{
@ -372,7 +331,7 @@ TEST(http_method)
req.url = "/get_only";
app.handle(req, res);
ASSERT_EQUAL("get", res.body);
REQUIRE("get" == res.body);
}
{
@ -383,7 +342,7 @@ TEST(http_method)
req.method = "PATCH"_method;
app.handle(req, res);
ASSERT_EQUAL("patch", res.body);
REQUIRE("patch" == res.body);
}
{
@ -394,7 +353,7 @@ TEST(http_method)
req.method = "PURGE"_method;
app.handle(req, res);
ASSERT_EQUAL("purge", res.body);
REQUIRE("purge" == res.body);
}
{
@ -405,7 +364,7 @@ TEST(http_method)
req.method = "POST"_method;
app.handle(req, res);
ASSERT_NOTEQUAL("get", res.body);
REQUIRE("get" != res.body);
}
{
@ -416,12 +375,12 @@ TEST(http_method)
req.method = "POST"_method;
app.handle(req, res);
ASSERT_EQUAL(405, res.code);
REQUIRE(405 == res.code);
}
}
TEST(server_handling_error_request)
TEST_CASE("server_handling_error_request")
{
static char buf[2048];
SimpleApp app;
@ -442,7 +401,7 @@ TEST(server_handling_error_request)
try
{
c.receive(asio::buffer(buf, 2048));
fail();
FAIL_CHECK();
}
catch(std::exception& e)
{
@ -452,7 +411,7 @@ TEST(server_handling_error_request)
app.stop();
}
TEST(multi_server)
TEST_CASE("multi_server")
{
static char buf[2048];
SimpleApp app1, app2;
@ -478,7 +437,7 @@ TEST(multi_server)
c.send(asio::buffer(sendmsg));
size_t recved = c.receive(asio::buffer(buf, 2048));
ASSERT_EQUAL('A', buf[recved-1]);
REQUIRE('A' == buf[recved-1]);
}
{
@ -492,14 +451,14 @@ TEST(multi_server)
}
size_t recved = c.receive(asio::buffer(buf, 2048));
ASSERT_EQUAL('B', buf[recved-1]);
REQUIRE('B' == buf[recved-1]);
}
app1.stop();
app2.stop();
}
TEST(json_read)
TEST_CASE("json_read")
{
{
const char* json_error_tests[] =
@ -521,7 +480,7 @@ TEST(json_read)
auto x = json::load(s);
if (x)
{
fail("should fail to parse ", s);
FAIL_CHECK(std::string("should fail to parse ") + s);
return;
}
}
@ -529,54 +488,54 @@ TEST(json_read)
auto x = json::load(R"({"message":"hello, world"})");
if (!x)
fail("fail to parse");
ASSERT_EQUAL("hello, world", x["message"]);
ASSERT_EQUAL(1, x.size());
ASSERT_EQUAL(false, x.has("mess"));
ASSERT_THROW(x["mess"]);
FAIL_CHECK("fail to parse");
REQUIRE("hello, world" == x["message"]);
REQUIRE(1 == x.size());
REQUIRE(false == x.has("mess"));
REQUIRE_THROWS(x["mess"]);
// TODO returning false is better than exception
//ASSERT_THROW(3 == x["message"]);
ASSERT_EQUAL(12, x["message"].size());
REQUIRE(12 == x["message"].size());
std::string s = R"({"int":3, "ints" :[1,2,3,4,5], "bigint":1234567890 })";
auto y = json::load(s);
ASSERT_EQUAL(3, y["int"]);
ASSERT_EQUAL(3.0, y["int"]);
ASSERT_NOTEQUAL(3.01, y["int"]);
ASSERT_EQUAL(5, y["ints"].size());
ASSERT_EQUAL(1, y["ints"][0]);
ASSERT_EQUAL(2, y["ints"][1]);
ASSERT_EQUAL(3, y["ints"][2]);
ASSERT_EQUAL(4, y["ints"][3]);
ASSERT_EQUAL(5, y["ints"][4]);
ASSERT_EQUAL(1u, y["ints"][0]);
ASSERT_EQUAL(1.f, y["ints"][0]);
REQUIRE(3 == y["int"]);
REQUIRE(3.0 == y["int"]);
REQUIRE(3.01 != y["int"]);
REQUIRE(5 == y["ints"].size());
REQUIRE(1 == y["ints"][0]);
REQUIRE(2 == y["ints"][1]);
REQUIRE(3 == y["ints"][2]);
REQUIRE(4 == y["ints"][3]);
REQUIRE(5 == y["ints"][4]);
REQUIRE(1u == y["ints"][0]);
REQUIRE(1.f == y["ints"][0]);
int q = (int)y["ints"][1];
ASSERT_EQUAL(2, q);
REQUIRE(2 == q);
q = y["ints"][2].i();
ASSERT_EQUAL(3, q);
ASSERT_EQUAL(1234567890, y["bigint"]);
REQUIRE(3 == q);
REQUIRE(1234567890 == y["bigint"]);
std::string s2 = R"({"bools":[true, false], "doubles":[1.2, -3.4]})";
auto z = json::load(s2);
ASSERT_EQUAL(2, z["bools"].size());
ASSERT_EQUAL(2, z["doubles"].size());
ASSERT_EQUAL(true, z["bools"][0].b());
ASSERT_EQUAL(false, z["bools"][1].b());
ASSERT_EQUAL(1.2, z["doubles"][0].d());
ASSERT_EQUAL(-3.4, z["doubles"][1].d());
REQUIRE(2 == z["bools"].size());
REQUIRE(2 == z["doubles"].size());
REQUIRE(true == z["bools"][0].b());
REQUIRE(false == z["bools"][1].b());
REQUIRE(1.2 == z["doubles"][0].d());
REQUIRE(-3.4 == z["doubles"][1].d());
std::string s3 = R"({"uint64": 18446744073709551615})";
auto z1 = json::load(s3);
ASSERT_EQUAL(18446744073709551615ull, z1["uint64"].u());
REQUIRE(18446744073709551615ull == z1["uint64"].u());
std::ostringstream os;
os << z1["uint64"];
ASSERT_EQUAL("18446744073709551615", os.str());
REQUIRE("18446744073709551615" == os.str());
}
TEST(json_read_real)
TEST_CASE("json_read_real")
{
vector<std::string> v{"0.036303908355795146", "0.18320417789757412",
"0.05319940476190476", "0.15224702380952382", "0", "0.3296201145552561",
@ -595,106 +554,106 @@ TEST(json_read_real)
for(auto x:v)
{
CROW_LOG_DEBUG << x;
ASSERT_EQUAL(json::load(x).d(), boost::lexical_cast<double>(x));
REQUIRE(json::load(x).d() == boost::lexical_cast<double>(x));
}
auto ret = json::load(R"---({"balloons":[{"mode":"ellipse","left":0.036303908355795146,"right":0.18320417789757412,"top":0.05319940476190476,"bottom":0.15224702380952382,"index":"0"},{"mode":"ellipse","left":0.3296201145552561,"right":0.47921580188679247,"top":0.05873511904761905,"bottom":0.1577827380952381,"index":"1"},{"mode":"ellipse","left":0.4996841307277628,"right":0.6425412735849056,"top":0.052113095238095236,"bottom":0.12830357142857143,"index":"2"},{"mode":"ellipse","left":0.7871041105121294,"right":0.954220013477089,"top":0.05869047619047619,"bottom":0.1625,"index":"3"},{"mode":"ellipse","left":0.8144794474393531,"right":0.9721613881401617,"top":0.1399404761904762,"bottom":0.24470238095238095,"index":"4"},{"mode":"ellipse","left":0.04527459568733154,"right":0.2096950808625337,"top":0.35267857142857145,"bottom":0.42791666666666667,"index":"5"},{"mode":"ellipse","left":0.855731974393531,"right":0.9352467991913747,"top":0.3816220238095238,"bottom":0.4282886904761905,"index":"6"},{"mode":"ellipse","left":0.39414167789757415,"right":0.5316079851752021,"top":0.3809375,"bottom":0.4571279761904762,"index":"7"},{"mode":"ellipse","left":0.03522995283018868,"right":0.1915641846361186,"top":0.6164136904761904,"bottom":0.7192708333333333,"index":"8"},{"mode":"ellipse","left":0.05675117924528302,"right":0.21308541105121293,"top":0.7045386904761904,"bottom":0.8016815476190476,"index":"9"}]})---");
ASSERT_TRUE(ret);
REQUIRE(ret);
}
TEST(json_read_unescaping)
TEST_CASE("json_read_unescaping")
{
{
auto x = json::load(R"({"data":"\ud55c\n\t\r"})");
if (!x)
{
fail("fail to parse");
FAIL_CHECK("fail to parse");
return;
}
ASSERT_EQUAL(6, x["data"].size());
ASSERT_EQUAL("\n\t\r", x["data"]);
REQUIRE(6 == x["data"].size());
REQUIRE("\n\t\r" == x["data"]);
}
{
// multiple r_string instance
auto x = json::load(R"({"data":"\ud55c\n\t\r"})");
auto a = x["data"].s();
auto b = x["data"].s();
ASSERT_EQUAL(6, a.size());
ASSERT_EQUAL(6, b.size());
ASSERT_EQUAL(6, x["data"].size());
REQUIRE(6 == a.size());
REQUIRE(6 == b.size());
REQUIRE(6 == x["data"].size());
}
}
TEST(json_write)
TEST_CASE("json_write")
{
json::wvalue x;
x["message"] = "hello world";
ASSERT_EQUAL(R"({"message":"hello world"})", json::dump(x));
REQUIRE(R"({"message":"hello world"})" == json::dump(x));
x["message"] = std::string("string value");
ASSERT_EQUAL(R"({"message":"string value"})", json::dump(x));
REQUIRE(R"({"message":"string value"})" == json::dump(x));
x["message"]["x"] = 3;
ASSERT_EQUAL(R"({"message":{"x":3}})", json::dump(x));
REQUIRE(R"({"message":{"x":3}})" == json::dump(x));
x["message"]["y"] = 5;
ASSERT_TRUE(R"({"message":{"x":3,"y":5}})" == json::dump(x) || R"({"message":{"y":5,"x":3}})" == json::dump(x));
REQUIRE((R"({"message":{"x":3,"y":5}})" == json::dump(x) || R"({"message":{"y":5,"x":3}})" == json::dump(x)));
x["message"] = 5.5;
ASSERT_EQUAL(R"({"message":5.5})", json::dump(x));
REQUIRE(R"({"message":5.5})" == json::dump(x));
x["message"] = 1234567890;
ASSERT_EQUAL(R"({"message":1234567890})", json::dump(x));
REQUIRE(R"({"message":1234567890})" == json::dump(x));
json::wvalue y;
y["scores"][0] = 1;
y["scores"][1] = "king";
y["scores"][2] = 3.5;
ASSERT_EQUAL(R"({"scores":[1,"king",3.5]})", json::dump(y));
REQUIRE(R"({"scores":[1,"king",3.5]})" == json::dump(y));
y["scores"][2][0] = "real";
y["scores"][2][1] = false;
y["scores"][2][2] = true;
ASSERT_EQUAL(R"({"scores":[1,"king",["real",false,true]]})", json::dump(y));
REQUIRE(R"({"scores":[1,"king",["real",false,true]]})" == json::dump(y));
y["scores"]["a"]["b"]["c"] = nullptr;
ASSERT_EQUAL(R"({"scores":{"a":{"b":{"c":null}}}})", json::dump(y));
REQUIRE(R"({"scores":{"a":{"b":{"c":null}}}})" == json::dump(y));
y["scores"] = std::vector<int>{1,2,3};
ASSERT_EQUAL(R"({"scores":[1,2,3]})", json::dump(y));
REQUIRE(R"({"scores":[1,2,3]})" == json::dump(y));
}
TEST(json_copy_r_to_w_to_r)
TEST_CASE("json_copy_r_to_w_to_r")
{
json::rvalue r = json::load(R"({"smallint":2,"bigint":2147483647,"fp":23.43,"fpsc":2.343e1,"str":"a string","trueval":true,"falseval":false,"nullval":null,"listval":[1,2,"foo","bar"],"obj":{"member":23,"other":"baz"}})");
json::wvalue w{r};
json::rvalue x = json::load(json::dump(w)); // why no copy-ctor wvalue -> rvalue?
ASSERT_EQUAL(2, x["smallint"]);
ASSERT_EQUAL(2147483647, x["bigint"]);
ASSERT_EQUAL(23.43, x["fp"]);
ASSERT_EQUAL(23.43, x["fpsc"]);
ASSERT_EQUAL("a string", x["str"]);
ASSERT_TRUE(true == x["trueval"].b());
ASSERT_TRUE(false == x["falseval"].b());
ASSERT_TRUE(json::type::Null == x["nullval"].t());
ASSERT_EQUAL(4u, x["listval"].size());
ASSERT_EQUAL(1, x["listval"][0]);
ASSERT_EQUAL(2, x["listval"][1]);
ASSERT_EQUAL("foo", x["listval"][2]);
ASSERT_EQUAL("bar", x["listval"][3]);
ASSERT_EQUAL(23, x["obj"]["member"]);
ASSERT_EQUAL("member", x["obj"]["member"].key());
ASSERT_EQUAL("baz", x["obj"]["other"]);
ASSERT_EQUAL("other", x["obj"]["other"].key());
REQUIRE(2 == x["smallint"]);
REQUIRE(2147483647 == x["bigint"]);
REQUIRE(23.43 == x["fp"]);
REQUIRE(23.43 == x["fpsc"]);
REQUIRE("a string" == x["str"]);
REQUIRE(x["trueval"].b());
REQUIRE_FALSE(x["falseval"].b());
REQUIRE(json::type::Null == x["nullval"].t());
REQUIRE(4u == x["listval"].size());
REQUIRE(1 == x["listval"][0]);
REQUIRE(2 == x["listval"][1]);
REQUIRE("foo" == x["listval"][2]);
REQUIRE("bar" == x["listval"][3]);
REQUIRE(23 == x["obj"]["member"]);
REQUIRE("member" == x["obj"]["member"].key());
REQUIRE("baz" == x["obj"]["other"]);
REQUIRE("other" == x["obj"]["other"].key());
}
TEST(template_basic)
TEST_CASE("template_basic")
{
auto t = crow::mustache::compile(R"---(attack of {{name}})---");
crow::mustache::context ctx;
ctx["name"] = "killer tomatoes";
auto result = t.render(ctx);
ASSERT_EQUAL("attack of killer tomatoes", result);
REQUIRE("attack of killer tomatoes" == result);
//crow::mustache::load("basic.mustache");
}
TEST(template_load)
TEST_CASE("template_load")
{
crow::mustache::set_base(".");
ofstream("test.mustache") << R"---(attack of {{name}})---";
@ -702,39 +661,11 @@ TEST(template_load)
crow::mustache::context ctx;
ctx["name"] = "killer tomatoes";
auto result = t.render(ctx);
ASSERT_EQUAL("attack of killer tomatoes", result);
REQUIRE("attack of killer tomatoes" == result);
unlink("test.mustache");
}
int testmain()
{
bool failed = false;
for(auto t:tests)
{
failed__ = false;
try
{
//cerr << typeid(*t).name() << endl;
t->test();
}
catch(std::exception& e)
{
fail(e.what());
}
if (failed__)
{
cerr << "F";
cerr << '\t' << typeid(*t).name() << endl;
failed = true;
}
else
cerr << ".";
}
cerr<<endl;
return failed ? -1 : 0;
}
TEST(black_magic)
TEST_CASE("black_magic")
{
using namespace black_magic;
static_assert(std::is_same<void, last_element_type<int, char, void>::type>::value, "last_element_type");
@ -767,7 +698,7 @@ struct NullSimpleMiddleware
};
TEST(middleware_simple)
TEST_CASE("middleware_simple")
{
App<NullMiddleware, NullSimpleMiddleware> app;
decltype(app)::server_t server(&app, LOCALHOST_ADDRESS, 45451);
@ -851,7 +782,7 @@ struct ThirdMW
}
};
TEST(middleware_context)
TEST_CASE("middleware_context")
{
static char buf[2048];
@ -903,15 +834,15 @@ TEST(middleware_context)
}
{
auto& out = test_middleware_context_vector;
ASSERT_EQUAL(1, x);
ASSERT_EQUAL(7, out.size());
ASSERT_EQUAL("1 before", out[0]);
ASSERT_EQUAL("2 before", out[1]);
ASSERT_EQUAL("3 before", out[2]);
ASSERT_EQUAL("handle", out[3]);
ASSERT_EQUAL("3 after", out[4]);
ASSERT_EQUAL("2 after", out[5]);
ASSERT_EQUAL("1 after", out[6]);
REQUIRE(1 == x);
REQUIRE(7 == out.size());
REQUIRE("1 before" == out[0]);
REQUIRE("2 before" == out[1]);
REQUIRE("3 before" == out[2]);
REQUIRE("handle" == out[3]);
REQUIRE("3 after" == out[4]);
REQUIRE("2 after" == out[5]);
REQUIRE("1 after" == out[6]);
}
std::string sendmsg2 = "GET /break\r\n\r\n";
{
@ -925,16 +856,16 @@ TEST(middleware_context)
}
{
auto& out = test_middleware_context_vector;
ASSERT_EQUAL(4, out.size());
ASSERT_EQUAL("1 before", out[0]);
ASSERT_EQUAL("2 before", out[1]);
ASSERT_EQUAL("2 after", out[2]);
ASSERT_EQUAL("1 after", out[3]);
REQUIRE(4 == out.size());
REQUIRE("1 before" == out[0]);
REQUIRE("2 before" == out[1]);
REQUIRE("2 after" == out[2]);
REQUIRE("1 after" == out[3]);
}
app.stop();
}
TEST(middleware_cookieparser)
TEST_CASE("middleware_cookieparser")
{
static char buf[2048];
@ -973,15 +904,15 @@ TEST(middleware_cookieparser)
c.close();
}
{
ASSERT_EQUAL("value1", value1);
ASSERT_EQUAL("val=ue2", value2);
ASSERT_EQUAL("val\"ue3", value3);
ASSERT_EQUAL("val\"ue4", value4);
REQUIRE("value1" == value1);
REQUIRE("val=ue2" == value2);
REQUIRE("val\"ue3" == value3);
REQUIRE("val\"ue4" == value4);
}
app.stop();
}
TEST(bug_quick_repeated_request)
TEST_CASE("bug_quick_repeated_request")
{
static char buf[2048];
@ -1012,7 +943,7 @@ TEST(bug_quick_repeated_request)
c.send(asio::buffer(sendmsg));
size_t received = c.receive(asio::buffer(buf, 2048));
ASSERT_EQUAL("hello", std::string(buf + received - 5, buf + received));
REQUIRE("hello" == std::string(buf + received - 5, buf + received));
}
c.close();
}));
@ -1021,7 +952,7 @@ TEST(bug_quick_repeated_request)
app.stop();
}
TEST(simple_url_params)
TEST_CASE("simple_url_params")
{
static char buf[2048];
@ -1056,7 +987,7 @@ TEST(simple_url_params)
stringstream ss;
ss << last_url_params;
ASSERT_EQUAL("[ ]", ss.str());
REQUIRE("[ ]" == ss.str());
}
// check single presence
sendmsg = "GET /params?foobar\r\n\r\n";
@ -1067,9 +998,9 @@ TEST(simple_url_params)
c.receive(asio::buffer(buf, 2048));
c.close();
ASSERT_TRUE(last_url_params.get("missing") == nullptr);
ASSERT_TRUE(last_url_params.get("foobar") != nullptr);
ASSERT_TRUE(last_url_params.get_list("missing").empty());
REQUIRE(last_url_params.get("missing") == nullptr);
REQUIRE(last_url_params.get("foobar") != nullptr);
REQUIRE(last_url_params.get_list("missing").empty());
}
// check multiple presence
sendmsg = "GET /params?foo&bar&baz\r\n\r\n";
@ -1080,10 +1011,10 @@ TEST(simple_url_params)
c.receive(asio::buffer(buf, 2048));
c.close();
ASSERT_TRUE(last_url_params.get("missing") == nullptr);
ASSERT_TRUE(last_url_params.get("foo") != nullptr);
ASSERT_TRUE(last_url_params.get("bar") != nullptr);
ASSERT_TRUE(last_url_params.get("baz") != nullptr);
REQUIRE(last_url_params.get("missing") == nullptr);
REQUIRE(last_url_params.get("foo") != nullptr);
REQUIRE(last_url_params.get("bar") != nullptr);
REQUIRE(last_url_params.get("baz") != nullptr);
}
// check single value
sendmsg = "GET /params?hello=world\r\n\r\n";
@ -1094,7 +1025,7 @@ TEST(simple_url_params)
c.receive(asio::buffer(buf, 2048));
c.close();
ASSERT_EQUAL(string(last_url_params.get("hello")), "world");
REQUIRE(string(last_url_params.get("hello")) == "world");
}
// check multiple value
sendmsg = "GET /params?hello=world&left=right&up=down\r\n\r\n";
@ -1105,9 +1036,9 @@ TEST(simple_url_params)
c.receive(asio::buffer(buf, 2048));
c.close();
ASSERT_EQUAL(string(last_url_params.get("hello")), "world");
ASSERT_EQUAL(string(last_url_params.get("left")), "right");
ASSERT_EQUAL(string(last_url_params.get("up")), "down");
REQUIRE(string(last_url_params.get("hello")) == "world");
REQUIRE(string(last_url_params.get("left")) == "right");
REQUIRE(string(last_url_params.get("up")) == "down");
}
// check multiple value, multiple types
sendmsg = "GET /params?int=100&double=123.45&boolean=1\r\n\r\n";
@ -1118,9 +1049,9 @@ TEST(simple_url_params)
c.receive(asio::buffer(buf, 2048));
c.close();
ASSERT_EQUAL(boost::lexical_cast<int>(last_url_params.get("int")), 100);
ASSERT_EQUAL(boost::lexical_cast<double>(last_url_params.get("double")), 123.45);
ASSERT_EQUAL(boost::lexical_cast<bool>(last_url_params.get("boolean")), true);
REQUIRE(boost::lexical_cast<int>(last_url_params.get("int")) == 100);
REQUIRE(boost::lexical_cast<double>(last_url_params.get("double")) == 123.45);
REQUIRE(boost::lexical_cast<bool>(last_url_params.get("boolean")));
}
// check single array value
sendmsg = "GET /params?tmnt[]=leonardo\r\n\r\n";
@ -1132,9 +1063,9 @@ TEST(simple_url_params)
c.receive(asio::buffer(buf, 2048));
c.close();
ASSERT_TRUE(last_url_params.get("tmnt") == nullptr);
ASSERT_EQUAL(last_url_params.get_list("tmnt").size(), 1);
ASSERT_EQUAL(string(last_url_params.get_list("tmnt")[0]), "leonardo");
REQUIRE(last_url_params.get("tmnt") == nullptr);
REQUIRE(last_url_params.get_list("tmnt").size() == 1);
REQUIRE(string(last_url_params.get_list("tmnt")[0]) == "leonardo");
}
// check multiple array value
sendmsg = "GET /params?tmnt[]=leonardo&tmnt[]=donatello&tmnt[]=raphael\r\n\r\n";
@ -1146,15 +1077,15 @@ TEST(simple_url_params)
c.receive(asio::buffer(buf, 2048));
c.close();
ASSERT_EQUAL(last_url_params.get_list("tmnt").size(), 3);
ASSERT_EQUAL(string(last_url_params.get_list("tmnt")[0]), "leonardo");
ASSERT_EQUAL(string(last_url_params.get_list("tmnt")[1]), "donatello");
ASSERT_EQUAL(string(last_url_params.get_list("tmnt")[2]), "raphael");
REQUIRE(last_url_params.get_list("tmnt").size() == 3);
REQUIRE(string(last_url_params.get_list("tmnt")[0]) == "leonardo");
REQUIRE(string(last_url_params.get_list("tmnt")[1]) == "donatello");
REQUIRE(string(last_url_params.get_list("tmnt")[2]) == "raphael");
}
app.stop();
}
TEST(route_dynamic)
TEST_CASE("route_dynamic")
{
SimpleApp app;
int x = 1;
@ -1187,7 +1118,7 @@ TEST(route_dynamic)
([](){
return "";
});
fail();
FAIL_CHECK();
}
catch(std::exception&)
{
@ -1197,7 +1128,7 @@ TEST(route_dynamic)
try
{
app.validate();
fail();
FAIL_CHECK();
}
catch(std::exception&)
{
@ -1208,33 +1139,32 @@ TEST(route_dynamic)
response res;
req.url = "/";
app.handle(req, res);
ASSERT_EQUAL(x, 2);
REQUIRE(x == 2);
}
{
request req;
response res;
req.url = "/set_int/42";
app.handle(req, res);
ASSERT_EQUAL(x, 42);
REQUIRE(x == 42);
}
{
request req;
response res;
req.url = "/set5";
app.handle(req, res);
ASSERT_EQUAL(x, 5);
REQUIRE(x == 5);
}
{
request req;
response res;
req.url = "/set4";
app.handle(req, res);
ASSERT_EQUAL(x, 4);
REQUIRE(x == 4);
}
}
#include <sys/stat.h>
TEST(send_file)
TEST_CASE("send_file")
{
SimpleApp app;
@ -1260,17 +1190,12 @@ TEST(send_file)
app.handle(req, res);
struct stat statbuf;
int statResult;
stat("tests/img/cat.jpg", &statbuf);
statResult = stat("tests/img/cat.jpg", &statbuf);
ASSERT_EQUAL(200, res.code);
ASSERT_EQUAL("image/jpeg", res.headers.find("Content-Type")->second);
ASSERT_EQUAL(to_string(statbuf.st_size), res.headers.find("Content-Length")->second);
REQUIRE(200 == res.code);
REQUIRE("image/jpeg" == res.headers.find("Content-Type")->second);
REQUIRE(to_string(statbuf.st_size) == res.headers.find("Content-Length")->second);
}
{
@ -1281,10 +1206,6 @@ TEST(send_file)
app.handle(req, res);
ASSERT_EQUAL(404, res.code);
REQUIRE(404 == res.code);
}
}
int main()
{
return testmain();
}