xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
<root> / tests / parsing / compares.c (082cdcde96d0844824ef118ce3ce2e243f634a76) (2,356B) (mode 100644) [raw]
#include <stic.h>

#include <stdlib.h> /* free() */

#include "../../src/engine/parsing.h"
#include "../../src/engine/var.h"

#include "asserts.h"

TEST(eq_compare_true)
{
	ASSERT_OK("'a'=='a'", "1");
	ASSERT_OK("1==1", "1");
}

TEST(eq_compare_false)
{
	ASSERT_OK("'a'=='b'", "0");
	ASSERT_OK("1==-1", "0");
}

TEST(ne_compare_true)
{
	ASSERT_OK("'a'!='b'", "1");
	ASSERT_OK("-1!=1", "1");
}

TEST(ne_compare_false)
{
	ASSERT_OK("'a'!='a'", "0");
	ASSERT_OK("0!=0", "0");
}

TEST(lt_compare_true)
{
	ASSERT_OK("1<2", "1");
	ASSERT_OK("'a'<'b'", "1");
}

TEST(lt_compare_false)
{
	ASSERT_OK("2<1", "0");
	ASSERT_OK("' '<'a'", "1");
}

TEST(le_compare_true)
{
	ASSERT_OK("1<=1", "1");
	ASSERT_OK("-1<=1", "1");
	ASSERT_OK("'a'<='b'", "1");
	ASSERT_OK("'b'<='b'", "1");
}

TEST(le_compare_false)
{
	ASSERT_OK("3<=2", "0");
	ASSERT_OK("'c'<='b'", "0");
}

TEST(ge_compare_true)
{
	ASSERT_OK("1>=1", "1");
	ASSERT_OK("2>=1", "1");
	ASSERT_OK("'b'>='a'", "1");
	ASSERT_OK("'b'>='b'", "1");
}

TEST(ge_compare_false)
{
	ASSERT_OK("0>=1", "0");
	ASSERT_OK("'b'>='c'", "0");
}

TEST(gt_compare_true)
{
	ASSERT_OK("2>-1", "1");
	ASSERT_OK("'b'>'a'", "1");
}

TEST(gt_compare_false)
{
	ASSERT_OK("1>1", "0");
	ASSERT_OK("'b'>'b'", "0");
}

TEST(compares_prefer_numbers)
{
	ASSERT_OK("'2'>'b'", "0");
	ASSERT_OK("2>'b'", "1");
}

TEST(compares_convert_string_to_numbers)
{
	ASSERT_OK("2>'b'", "1");
	ASSERT_OK("2>'9b'", "0");
}

TEST(leading_spaces_ok)
{
	ASSERT_OK("     'a'!='a'", "0");
}

TEST(trailing_spaces_ok)
{
	ASSERT_OK("'a'!='a'       ", "0");
}

TEST(spaces_before_op_ok)
{
	ASSERT_OK("'a'      !='a'", "0");
}

TEST(spaces_after_op_ok)
{
	ASSERT_OK("'a'!=         'a'", "0");
}

TEST(spaces_in_op_fail)
{
	ASSERT_FAIL("'a' ! = 'a'", PE_INVALID_EXPRESSION);
	ASSERT_FAIL("'a' = = 'a'", PE_INVALID_EXPRESSION);
	ASSERT_FAIL("'a' > = 'a'", PE_INVALID_EXPRESSION);
	ASSERT_FAIL("'a' < = 'a'", PE_INVALID_EXPRESSION);
}

TEST(wrong_op_fail)
{
	ASSERT_FAIL("'a' =! 'a'", PE_INVALID_EXPRESSION);
	ASSERT_FAIL("'a' => 'a'", PE_INVALID_EXPRESSION);
	ASSERT_FAIL("'a' =< 'a'", PE_INVALID_EXPRESSION);
}

TEST(ops_ignored_inside_strings)
{
	ASSERT_OK("'!= == <= >= !'", "!= == <= >= !");
	ASSERT_OK("\"!= == <= >= !\"", "!= == <= >= !");
}

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master