Commit 11cf36ea authored by Jonathan Hanks's avatar Jonathan Hanks

Merge branch 'debian' into 'debian'

Package 0.2.1

See merge request !4
parents c7f4118a 43229b80
Pipeline #46155 passed with stage
in 10 minutes and 15 seconds
ligo-channel-completion (0.2.1) unstable; urgency=medium
* Bug fix for completion sorting and selection
-- Jonathan Hanks <jonathan.hanks@ligo.org> Mon, 28 Jan 2019 11:25:47 -0800
ligo-channel-completion (0.2) unstable; urgency=medium
* Added system level test
......
......@@ -4,7 +4,7 @@ Priority: optional
Maintainer: Jameson Graef Rollins <jrollins@finestructure.net>
Build-Depends:
cmake,
debhelper (>= 10),
debhelper (>= 9),
libboost-dev,
libpstreams-dev
Standards-Version: 3.9.8
......
......@@ -64,16 +64,28 @@ namespace completion
inline bool
simple_comparison( const channel& a, const channel& b )
{
return std::strcmp( a.name.c_str( ), b.name.c_str( ) ) < 0;
return a.name < b.name;
}
inline bool
key_comparison( const std::string& key, const channel& element )
class key_comparison
{
int result =
std::strncmp( key.c_str( ), element.name.c_str( ), key.size( ) );
return result < 0;
}
public:
explicit key_comparison( std::string::size_type key_len )
: key_len_( key_len )
{
}
bool
operator( )( const std::string& str1, const std::string& str2 ) const
{
std::string::size_type n =
std::min( key_len_, std::max( str1.size( ), str2.size( ) ) );
int result = std::strncmp( str1.c_str( ), str2.c_str( ), n );
return result < 0;
}
private:
std::string::size_type key_len_;
};
inline Database
load_database( const std::string& path )
......@@ -105,9 +117,12 @@ namespace completion
boost::make_transform_iterator( begin_it_, detail::project_name );
auto end_it =
boost::make_transform_iterator( end_it_, detail::project_name );
auto lower = std::lower_bound( begin_it, end_it, key, key_comparison );
auto upper = std::upper_bound( lower, end_it, key, key_comparison );
auto key_size = key.size( );
auto key_size = key.size( );
key_comparison comp( key_size );
auto lower = std::lower_bound( begin_it, end_it, key, comp );
auto upper = std::upper_bound( lower, end_it, key, comp );
std::for_each(
lower, upper, [key_size, &results]( const std::string& entry ) {
static const std::string delimiters( "-_" );
......@@ -148,4 +163,4 @@ namespace completion
}
}
#endif // LIGO_CHANNEL_COMPLETION_HH
\ No newline at end of file
#endif // LIGO_CHANNEL_COMPLETION_HH
......@@ -220,6 +220,27 @@ TEST_CASE( "Basic completion behavior" )
}
}
TEST_CASE( "Channel completion should not remove user input" )
{
completion::Database db;
db.channels = {
{ "H0:VAC-SYSTEM" }, { "H0:VAC-SYSTEM_1_a" },
{ "H0:VAC-SYSTEM_1_b" }, { "H0:VAC-SYSTEM_1_c" },
{ "H0:VAC-SYSTEM_1_d" }, { "H0:VAC-SYSTEM_1_e" },
{ "H0:VAC-SYSTEM_1_f" },
};
{
std::vector< std::string > expected = {
"H0:VAC-SYSTEM_1_a", "H0:VAC-SYSTEM_1_b", "H0:VAC-SYSTEM_1_c",
"H0:VAC-SYSTEM_1_d", "H0:VAC-SYSTEM_1_e", "H0:VAC-SYSTEM_1_f",
};
completion::string_list results = completion::search(
db.channels.begin( ), db.channels.end( ), "H0:VAC-SYSTEM_1" );
REQUIRE( results == expected );
}
}
TEST_CASE( "Basic DB sorting" )
{
completion::Database input;
......
......@@ -253,6 +253,20 @@ TEST_CASE( "Basic completion behavior with an specified database with spaces "
run_search_test( input, "H0:VAC-SYSTEM_1", expected );
}
TEST_CASE( "Completions should never remove user input" )
{
std::vector< std::string > input = {
"H0:VAC-SYSTEM", "H0:VAC-SYSTEM_1_a", "H0:VAC-SYSTEM_1_b",
"H0:VAC-SYSTEM_1_c", "H0:VAC-SYSTEM_1_d", "H0:VAC-SYSTEM_1_e",
"H0:VAC-SYSTEM_1_f",
};
std::vector< std::string > expected = {
"H0:VAC-SYSTEM_1_a", "H0:VAC-SYSTEM_1_b", "H0:VAC-SYSTEM_1_c",
"H0:VAC-SYSTEM_1_d", "H0:VAC-SYSTEM_1_e", "H0:VAC-SYSTEM_1_f",
};
run_search_test( input, "H0:VAC-SYSTEM_1", expected );
}
TEST_CASE( "Basic sorting with a specified input database" )
{
std::vector< std::string > input = {
......
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