Commit 666bc325 authored by Kirill Smelkov's avatar Kirill Smelkov

strings: tests: Move into strings_test.cpp from <- libgolang_test.cpp

parent 617b51b2
......@@ -14,6 +14,7 @@ include golang/fmt.h
include golang/fmt.cpp
include golang/strings.h
include golang/strings.cpp
include golang/strings_test.cpp
include golang/sync.h
include golang/sync.cpp
include golang/sync_test.cpp
......
/_context.cpp
/_golang.cpp
/_golang_test.cpp
/_strings_test.cpp
/_sync.cpp
/_sync_test.cpp
/_time.cpp
......@@ -230,11 +230,6 @@ cdef extern from * nogil:
extern void _test_global();
extern void _test_fmt_sprintf_cpp();
extern void _test_fmt_errorf_cpp();
extern void _test_strings_has_prefix();
extern void _test_strings_trim_prefix();
extern void _test_strings_has_suffix();
extern void _test_strings_trim_suffix();
extern void _test_strings_split();
"""
void _test_chan_cpp_refcount() except +topyexc
void _test_chan_cpp() except +topyexc
......@@ -249,11 +244,6 @@ cdef extern from * nogil:
void _test_global() except +topyexc
void _test_fmt_sprintf_cpp() except +topyexc
void _test_fmt_errorf_cpp() except +topyexc
void _test_strings_has_prefix() except +topyexc
void _test_strings_trim_prefix() except +topyexc
void _test_strings_has_suffix() except +topyexc
void _test_strings_trim_suffix() except +topyexc
void _test_strings_split() except +topyexc
def test_chan_cpp_refcount():
with nogil:
_test_chan_cpp_refcount()
......@@ -293,21 +283,6 @@ def test_fmt_sprintf_cpp(): # TODO move -> _fmt_test.pyx
def test_fmt_errorf_cpp():
with nogil:
_test_fmt_errorf_cpp()
def test_strings_has_prefix(): # TODO move -> _sync_test.pyx
with nogil:
_test_strings_has_prefix()
def test_strings_trim_prefix():
with nogil:
_test_strings_trim_prefix()
def test_strings_has_suffix():
with nogil:
_test_strings_has_suffix()
def test_strings_trim_suffix():
with nogil:
_test_strings_trim_suffix()
def test_strings_split():
with nogil:
_test_strings_split()
# helpers for pychan(dtype=X) py <-> c tests.
......
# -*- coding: utf-8 -*-
# cython: language_level=2
# distutils: language=c++
#
# Copyright (C) 2019-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
from __future__ import print_function, absolute_import
from golang cimport topyexc
# strings_test.cpp
cdef extern from * nogil:
"""
extern void _test_strings_has_prefix();
extern void _test_strings_trim_prefix();
extern void _test_strings_has_suffix();
extern void _test_strings_trim_suffix();
extern void _test_strings_split();
"""
void _test_strings_has_prefix() except +topyexc
void _test_strings_trim_prefix() except +topyexc
void _test_strings_has_suffix() except +topyexc
void _test_strings_trim_suffix() except +topyexc
void _test_strings_split() except +topyexc
def test_strings_has_prefix():
with nogil:
_test_strings_has_prefix()
def test_strings_trim_prefix():
with nogil:
_test_strings_trim_prefix()
def test_strings_has_suffix():
with nogil:
_test_strings_has_suffix()
def test_strings_trim_suffix():
with nogil:
_test_strings_trim_suffix()
def test_strings_split():
with nogil:
_test_strings_split()
......@@ -21,7 +21,6 @@
#include "golang/libgolang.h"
#include "golang/fmt.h"
#include "golang/strings.h"
#include "golang/time.h"
#include <stdio.h>
......@@ -705,97 +704,3 @@ void _test_fmt_errorf_cpp() {
const char *myfile = "myfile";
ASSERT_EQ(fmt::errorf(f, "read", myfile, myerror)->Error() , "read myfile: myerror");
}
// ---- strings:: ----
void _test_strings_has_prefix() {
ASSERT(strings::has_prefix("", "") == true);
ASSERT(strings::has_prefix("", "a") == false);
ASSERT(strings::has_prefix("", 'a') == false);
ASSERT(strings::has_prefix("b", "a") == false);
ASSERT(strings::has_prefix("b", 'a') == false);
ASSERT(strings::has_prefix("a", "a") == true);
ASSERT(strings::has_prefix("a", 'a') == true);
ASSERT(strings::has_prefix("a", "aa") == false);
ASSERT(strings::has_prefix("hello", "") == true);
ASSERT(strings::has_prefix("hello", "h") == true);
ASSERT(strings::has_prefix("hello", 'h') == true);
ASSERT(strings::has_prefix("hello", 'X') == false);
ASSERT(strings::has_prefix("hello", "he") == true);
ASSERT(strings::has_prefix("hello", "hel") == true);
ASSERT(strings::has_prefix("hello", "hez") == false);
ASSERT(strings::has_prefix("hello", "a") == false);
}
void _test_strings_trim_prefix() {
ASSERT_EQ(strings::trim_prefix("", "") , "");
ASSERT_EQ(strings::trim_prefix("", "a") , "");
ASSERT_EQ(strings::trim_prefix("", 'a') , "");
ASSERT_EQ(strings::trim_prefix("a", "") , "a");
ASSERT_EQ(strings::trim_prefix("a", "b") , "a");
ASSERT_EQ(strings::trim_prefix("a", 'b') , "a");
ASSERT_EQ(strings::trim_prefix("a", "a") , "");
ASSERT_EQ(strings::trim_prefix("a", 'a') , "");
ASSERT_EQ(strings::trim_prefix("a", "ab") , "a");
ASSERT_EQ(strings::trim_prefix("hello", "world") , "hello");
ASSERT_EQ(strings::trim_prefix("hello", "h") , "ello");
ASSERT_EQ(strings::trim_prefix("hello", 'h') , "ello");
ASSERT_EQ(strings::trim_prefix("hello", "he") , "llo");
ASSERT_EQ(strings::trim_prefix("hello", "hel") , "lo");
ASSERT_EQ(strings::trim_prefix("hello", "hez") , "hello");
}
void _test_strings_has_suffix() {
ASSERT(strings::has_suffix("", "") == true);
ASSERT(strings::has_suffix("", "a") == false);
ASSERT(strings::has_suffix("", 'a') == false);
ASSERT(strings::has_suffix("b", "a") == false);
ASSERT(strings::has_suffix("b", 'a') == false);
ASSERT(strings::has_suffix("a", "a") == true);
ASSERT(strings::has_suffix("a", 'a') == true);
ASSERT(strings::has_suffix("a", "aa") == false);
ASSERT(strings::has_suffix("hello", "") == true);
ASSERT(strings::has_suffix("hello", "o") == true);
ASSERT(strings::has_suffix("hello", 'o') == true);
ASSERT(strings::has_suffix("hello", 'X') == false);
ASSERT(strings::has_suffix("hello", "lo") == true);
ASSERT(strings::has_suffix("hello", "llo") == true);
ASSERT(strings::has_suffix("hello", "llz") == false);
ASSERT(strings::has_suffix("hello", "a") == false);
}
void _test_strings_trim_suffix() {
ASSERT_EQ(strings::trim_suffix("", "") , "");
ASSERT_EQ(strings::trim_suffix("", "a") , "");
ASSERT_EQ(strings::trim_suffix("", 'a') , "");
ASSERT_EQ(strings::trim_suffix("a", "") , "a");
ASSERT_EQ(strings::trim_suffix("a", "b") , "a");
ASSERT_EQ(strings::trim_suffix("a", 'b') , "a");
ASSERT_EQ(strings::trim_suffix("a", "a") , "");
ASSERT_EQ(strings::trim_suffix("a", 'a') , "");
ASSERT_EQ(strings::trim_suffix("a", "ab") , "a");
ASSERT_EQ(strings::trim_suffix("hello", "world") , "hello");
ASSERT_EQ(strings::trim_suffix("hello", "o") , "hell");
ASSERT_EQ(strings::trim_suffix("hello", 'o') , "hell");
ASSERT_EQ(strings::trim_suffix("hello", "lo") , "hel");
ASSERT_EQ(strings::trim_suffix("hello", "llo") , "he");
ASSERT_EQ(strings::trim_suffix("hello", "llz") , "hello");
}
void _test_strings_split() {
auto V = [](const std::initializer_list<string> &argv) -> vector<string> {
return argv;
};
ASSERT_EQ(strings::split("" , ' ') , V({}));
ASSERT_EQ(strings::split("a" , ' ') , V({"a"}));
ASSERT_EQ(strings::split("a " , ' ') , V({"a", ""}));
ASSERT_EQ(strings::split(" a" , ' ') , V({"", "a"}));
ASSERT_EQ(strings::split("ab " , ' ') , V({"ab", ""}));
ASSERT_EQ(strings::split("ab c" , ' ') , V({"ab", "c"}));
ASSERT_EQ(strings::split("ab cd" , ' ') , V({"ab", "cd"}));
ASSERT_EQ(strings::split("ab cd " , ' ') , V({"ab", "cd", ""}));
ASSERT_EQ(strings::split("ab cd e" , ' ') , V({"ab", "cd", "e"}));
ASSERT_EQ(strings::split(" ab cd e" , ' ') , V({"", "ab", "cd", "e"}));
ASSERT_EQ(strings::split(" ab cd e" , ' ') , V({"", "", "ab", "cd", "e"}));
}
// Copyright (C) 2019-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
#include "golang/strings.h"
#include <vector>
#include "golang/_testing.h"
using namespace golang;
using std::vector;
void _test_strings_has_prefix() {
ASSERT(strings::has_prefix("", "") == true);
ASSERT(strings::has_prefix("", "a") == false);
ASSERT(strings::has_prefix("", 'a') == false);
ASSERT(strings::has_prefix("b", "a") == false);
ASSERT(strings::has_prefix("b", 'a') == false);
ASSERT(strings::has_prefix("a", "a") == true);
ASSERT(strings::has_prefix("a", 'a') == true);
ASSERT(strings::has_prefix("a", "aa") == false);
ASSERT(strings::has_prefix("hello", "") == true);
ASSERT(strings::has_prefix("hello", "h") == true);
ASSERT(strings::has_prefix("hello", 'h') == true);
ASSERT(strings::has_prefix("hello", 'X') == false);
ASSERT(strings::has_prefix("hello", "he") == true);
ASSERT(strings::has_prefix("hello", "hel") == true);
ASSERT(strings::has_prefix("hello", "hez") == false);
ASSERT(strings::has_prefix("hello", "a") == false);
}
void _test_strings_trim_prefix() {
ASSERT_EQ(strings::trim_prefix("", "") , "");
ASSERT_EQ(strings::trim_prefix("", "a") , "");
ASSERT_EQ(strings::trim_prefix("", 'a') , "");
ASSERT_EQ(strings::trim_prefix("a", "") , "a");
ASSERT_EQ(strings::trim_prefix("a", "b") , "a");
ASSERT_EQ(strings::trim_prefix("a", 'b') , "a");
ASSERT_EQ(strings::trim_prefix("a", "a") , "");
ASSERT_EQ(strings::trim_prefix("a", 'a') , "");
ASSERT_EQ(strings::trim_prefix("a", "ab") , "a");
ASSERT_EQ(strings::trim_prefix("hello", "world") , "hello");
ASSERT_EQ(strings::trim_prefix("hello", "h") , "ello");
ASSERT_EQ(strings::trim_prefix("hello", 'h') , "ello");
ASSERT_EQ(strings::trim_prefix("hello", "he") , "llo");
ASSERT_EQ(strings::trim_prefix("hello", "hel") , "lo");
ASSERT_EQ(strings::trim_prefix("hello", "hez") , "hello");
}
void _test_strings_has_suffix() {
ASSERT(strings::has_suffix("", "") == true);
ASSERT(strings::has_suffix("", "a") == false);
ASSERT(strings::has_suffix("", 'a') == false);
ASSERT(strings::has_suffix("b", "a") == false);
ASSERT(strings::has_suffix("b", 'a') == false);
ASSERT(strings::has_suffix("a", "a") == true);
ASSERT(strings::has_suffix("a", 'a') == true);
ASSERT(strings::has_suffix("a", "aa") == false);
ASSERT(strings::has_suffix("hello", "") == true);
ASSERT(strings::has_suffix("hello", "o") == true);
ASSERT(strings::has_suffix("hello", 'o') == true);
ASSERT(strings::has_suffix("hello", 'X') == false);
ASSERT(strings::has_suffix("hello", "lo") == true);
ASSERT(strings::has_suffix("hello", "llo") == true);
ASSERT(strings::has_suffix("hello", "llz") == false);
ASSERT(strings::has_suffix("hello", "a") == false);
}
void _test_strings_trim_suffix() {
ASSERT_EQ(strings::trim_suffix("", "") , "");
ASSERT_EQ(strings::trim_suffix("", "a") , "");
ASSERT_EQ(strings::trim_suffix("", 'a') , "");
ASSERT_EQ(strings::trim_suffix("a", "") , "a");
ASSERT_EQ(strings::trim_suffix("a", "b") , "a");
ASSERT_EQ(strings::trim_suffix("a", 'b') , "a");
ASSERT_EQ(strings::trim_suffix("a", "a") , "");
ASSERT_EQ(strings::trim_suffix("a", 'a') , "");
ASSERT_EQ(strings::trim_suffix("a", "ab") , "a");
ASSERT_EQ(strings::trim_suffix("hello", "world") , "hello");
ASSERT_EQ(strings::trim_suffix("hello", "o") , "hell");
ASSERT_EQ(strings::trim_suffix("hello", 'o') , "hell");
ASSERT_EQ(strings::trim_suffix("hello", "lo") , "hel");
ASSERT_EQ(strings::trim_suffix("hello", "llo") , "he");
ASSERT_EQ(strings::trim_suffix("hello", "llz") , "hello");
}
void _test_strings_split() {
auto V = [](const std::initializer_list<string> &argv) -> vector<string> {
return argv;
};
ASSERT_EQ(strings::split("" , ' ') , V({}));
ASSERT_EQ(strings::split("a" , ' ') , V({"a"}));
ASSERT_EQ(strings::split("a " , ' ') , V({"a", ""}));
ASSERT_EQ(strings::split(" a" , ' ') , V({"", "a"}));
ASSERT_EQ(strings::split("ab " , ' ') , V({"ab", ""}));
ASSERT_EQ(strings::split("ab c" , ' ') , V({"ab", "c"}));
ASSERT_EQ(strings::split("ab cd" , ' ') , V({"ab", "cd"}));
ASSERT_EQ(strings::split("ab cd " , ' ') , V({"ab", "cd", ""}));
ASSERT_EQ(strings::split("ab cd e" , ' ') , V({"ab", "cd", "e"}));
ASSERT_EQ(strings::split(" ab cd e" , ' ') , V({"", "ab", "cd", "e"}));
ASSERT_EQ(strings::split(" ab cd e" , ' ') , V({"", "", "ab", "cd", "e"}));
}
# -*- coding: utf-8 -*-
# Copyright (C) 2019-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
from __future__ import print_function, absolute_import
from golang.golang_test import import_pyx_tests
import_pyx_tests("golang._strings_test")
......@@ -251,6 +251,10 @@ setup(
Ext('golang._context',
['golang/_context.pyx']),
Ext('golang._strings_test',
['golang/_strings_test.pyx',
'golang/strings_test.cpp']),
Ext('golang._sync',
['golang/_sync.pyx'],
dsos = ['golang.runtime.libpyxruntime'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment