Skip to content

Commit

Permalink
Merge pull request #10 from raquentin/context-specific-lexing
Browse files Browse the repository at this point in the history
feat: context-specific lexing
  • Loading branch information
raquentin authored Sep 8, 2024
2 parents cbfdd32 + ee9d161 commit 19c59ec
Show file tree
Hide file tree
Showing 20 changed files with 549 additions and 12,516 deletions.
58 changes: 28 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
name: C++ CI
name: CI Build and Test

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest

build:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up CMake
uses: lukka/[email protected]

- name: Install dependencies
run: sudo apt-get install -y libcurl4-openssl-dev

- name: Install Google Test
run: |
sudo apt-get install -y libgtest-dev
cd /usr/src/gtest
sudo cmake .
sudo make
sudo cp *.a /usr/lib
- name: Configure project
run: cmake -S . -B build

- name: Build project
run: cmake --build build

- name: Run Tests
run: ctest --test-dir build
- uses: actions/checkout@v2

- name: Configure CMake
run: |
mkdir build
cd build
cmake ..
- name: Build the project
run: |
cd build
cmake --build .
- name: Run tests
run: |
cd build
ctest
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.24)
project(raquest)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMAND ON)

include_directories(include)
Expand All @@ -9,6 +10,19 @@ add_subdirectory(src)
add_subdirectory(tests)

include(FetchContent)

FetchContent_Declare(
CLI11 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.3.2.zip)

FetchContent_Declare(
json
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)

FetchContent_Declare(
curl
URL https://github.com/curl/curl/releases/download/curl-7_81_0/curl-7.81.0.tar.gz
)

FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip)
Expand All @@ -18,6 +32,6 @@ set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(googletest)
FetchContent_MakeAvailable(googletest CLI11 json curl)

enable_testing()
20 changes: 10 additions & 10 deletions examples/post.raq
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[request]
POST "https://jsonplaceholder.typicode.com/posts"
POST https://jsonplaceholder.typicode.com/posts

[headers]
Authorization: Bearer exampletoken12345
Expand All @@ -9,14 +9,14 @@ Custom-Header: custom_value
[body type="json"]
{
"title": "foo",
"body": "bar",
"userId": 1
"age": 30,
"isActive": true,
"description": "here is the description"
}

[assertion on="status"]
201

[assertion on="response"]
{
"message": "foo"
}
[assertions]
status: 201
json_field: title ^foo$
json_field: age 30
json_field: isActive true
json_field: description here is the description
44 changes: 44 additions & 0 deletions include/assertions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once
#include "regex.hpp"
#include "response.hpp"
#include <optional>
#include <string>
#include <vector>

enum class FailedAssertionType {
UnexpectedStatusCode,
MissingHeader,
UnexpectedHeader,
MissingJsonField,
UnexpectedJsonField,
};

struct FailedAssertion {
FailedAssertionType type;
std::string message;
};

class Assertions {
public:
static Assertions create();

Assertions &status_codes(const std::vector<int> &expected_codes);
Assertions &header(const std::string &key, const std::string &expected_value);
Assertions &json_field(const std::string &key, const std::string &pattern);

std::optional<FailedAssertion> validate(const Response &response) const;

private:
std::vector<int> expected_status_codes;
std::vector<std::pair<std::string, std::string>> expected_headers;
std::vector<std::pair<std::string, Regex>> expected_json_fields;

Assertions();

std::optional<FailedAssertion>
validate_status_code(const Response &response) const;
std::optional<FailedAssertion>
validate_header(const Response &response) const;
std::optional<FailedAssertion>
validate_json_fields(const Response &response) const;
};
Loading

0 comments on commit 19c59ec

Please sign in to comment.