Skip to content

Commit 3a9a098

Browse files
committed
Unit test passing locally
1 parent 0b53484 commit 3a9a098

File tree

8 files changed

+58
-34
lines changed

8 files changed

+58
-34
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "couchbase_lite"
33
version = "3.1.10-0"
44
# The first three numbers correspond to the Couchbase Lite C release, the fourth number corresponds to the Doctolib release
5+
edition = "2021"
56

67
[dependencies]
78
enum_primitive = "*"

src/blob.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ pub struct BlobReader<'r> {
160160
stream_ref: *mut CBLBlobReadStream,
161161
}
162162

163-
impl<'r> CblRef for BlobReader<'r> {
163+
impl CblRef for BlobReader<'_> {
164164
type Output = *mut CBLBlobReadStream;
165165
fn get_ref(&self) -> Self::Output {
166166
self.stream_ref
167167
}
168168
}
169169

170-
impl<'r> std::io::Read for BlobReader<'r> {
170+
impl std::io::Read for BlobReader<'_> {
171171
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
172172
unsafe {
173173
check_io(|err| {
@@ -182,7 +182,7 @@ impl<'r> std::io::Read for BlobReader<'r> {
182182
}
183183
}
184184

185-
impl<'r> Drop for BlobReader<'r> {
185+
impl Drop for BlobReader<'_> {
186186
fn drop(&mut self) {
187187
unsafe {
188188
CBLBlobReader_Close(self.get_ref());
@@ -200,7 +200,7 @@ pub struct BlobWriter<'d> {
200200
db: PhantomData<&'d mut Database>,
201201
}
202202

203-
impl<'d> CblRef for BlobWriter<'d> {
203+
impl CblRef for BlobWriter<'_> {
204204
type Output = *mut CBLBlobWriteStream;
205205
fn get_ref(&self) -> Self::Output {
206206
self.stream_ref
@@ -222,7 +222,7 @@ impl<'d> BlobWriter<'d> {
222222
}
223223
}
224224

225-
impl<'r> std::io::Write for BlobWriter<'r> {
225+
impl std::io::Write for BlobWriter<'_> {
226226
fn write(&mut self, data: &[u8]) -> std::result::Result<usize, std::io::Error> {
227227
unsafe {
228228
check_io(|err| {
@@ -246,7 +246,7 @@ impl<'r> std::io::Write for BlobWriter<'r> {
246246
}
247247
}
248248

249-
impl<'r> Drop for BlobWriter<'r> {
249+
impl Drop for BlobWriter<'_> {
250250
fn drop(&mut self) {
251251
unsafe { CBLBlobWriter_Close(self.get_ref()) }
252252
}

src/fleece.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use std::fmt;
4242
use std::mem::MaybeUninit;
4343
use std::ptr;
4444
use std::str;
45-
use retain;
45+
use crate::retain;
4646

4747
//////// CONTAINER
4848

src/fleece_mutable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,14 @@ pub struct Slot<'s> {
442442
owner: PhantomData<&'s mut MutableDict>,
443443
}
444444

445-
impl<'s> CblRef for Slot<'s> {
445+
impl CblRef for Slot<'_> {
446446
type Output = FLSlot;
447447
fn get_ref(&self) -> Self::Output {
448448
self.cbl_ref
449449
}
450450
}
451451

452-
impl<'s> Slot<'s> {
452+
impl Slot<'_> {
453453
pub fn put_null(self) {
454454
unsafe { FLSlot_SetNull(self.get_ref()) }
455455
}

src/index.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ use crate::{
77
CBLQueryIndex, CBLQueryIndex_Name, CBLQueryIndex_Collection, CBLCollection_GetIndex,
88
},
99
error::{Result, failure},
10-
slice::from_str,
10+
slice::{from_str, from_c_str},
1111
QueryLanguage, Array,
1212
collection::Collection,
1313
check_error, retain,
1414
};
15+
use std::ffi::CString;
1516

1617
pub struct ValueIndexConfiguration {
1718
cbl_ref: CBLValueIndexConfiguration,
@@ -40,8 +41,11 @@ impl ValueIndexConfiguration {
4041
}
4142
}
4243

44+
#[derive(Debug)]
4345
pub struct ArrayIndexConfiguration {
4446
cbl_ref: CBLArrayIndexConfiguration,
47+
_path: CString,
48+
_expressions: CString,
4549
}
4650

4751
impl CblRef for ArrayIndexConfiguration {
@@ -64,14 +68,17 @@ impl ArrayIndexConfiguration {
6468
using comma delimiter. If the array specified by the path contains scalar values,
6569
the expressions should be left unset or set to null. */
6670
pub fn new(query_language: QueryLanguage, path: &str, expressions: &str) -> Self {
67-
let s_path = from_str(path);
68-
let s_expressions = from_str(expressions);
71+
let path_c = CString::new(path).unwrap();
72+
let expressions_c = CString::new(expressions).unwrap();
73+
6974
Self {
7075
cbl_ref: CBLArrayIndexConfiguration {
7176
expressionLanguage: query_language as u32,
72-
path: s_path.get_ref(),
73-
expressions: s_expressions.get_ref(),
77+
path: from_c_str(&path_c, path.len()).get_ref(),
78+
expressions: from_c_str(&expressions_c, expressions.len()).get_ref(),
7479
},
80+
_path: path_c,
81+
_expressions: expressions_c,
7582
}
7683
}
7784
}

src/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use crate::{
3030
Listener,
3131
};
3232

33-
use std::{os::raw::c_uint};
34-
use ListenerToken;
33+
use std::os::raw::c_uint;
34+
use crate::ListenerToken;
3535

3636
/** Query languages. */
3737
pub enum QueryLanguage {

src/slice.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ pub fn from_str(s: &str) -> Slice<&str> {
9898
)
9999
}
100100

101+
pub fn from_c_str(s: &CStr, len: usize) -> Slice<&CStr> {
102+
Slice::wrap(
103+
FLSlice {
104+
buf: s.as_ptr().cast::<c_void>(),
105+
size: len,
106+
},
107+
s,
108+
)
109+
}
110+
101111
pub fn from_bytes(s: &[u8]) -> Slice<&[u8]> {
102112
Slice::wrap(
103113
FLSlice {
@@ -114,7 +124,7 @@ impl FLSlice {
114124
if !self {
115125
return None;
116126
}
117-
return Some(std::slice::from_raw_parts(self.buf.cast::<u8>(), self.size));
127+
Some(std::slice::from_raw_parts(self.buf.cast::<u8>(), self.size))
118128
}
119129

120130
pub(crate) unsafe fn as_str<'a>(&self) -> Option<&'a str> {

tests/query_tests.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,10 @@ fn array_index() {
284284
// Index with one level of unnest
285285
let index_configuration = ArrayIndexConfiguration::new(QueryLanguage::N1QL, "likes", "");
286286

287-
assert!(default_collection
288-
.create_array_index("one_level", &index_configuration,)
289-
.unwrap());
287+
let result = default_collection
288+
.create_array_index("one_level", &index_configuration)
289+
.unwrap();
290+
assert!(result);
290291

291292
let query = Query::new(
292293
db,
@@ -305,18 +306,12 @@ fn array_index() {
305306
assert!(result.next().is_none());
306307

307308
// Index with two levels of unnest
308-
/*let index_configuration = ArrayIndexConfiguration::new(
309-
QueryLanguage::N1QL,
310-
"contacts[].phones",
311-
"",//"type",
312-
);
309+
let index_configuration =
310+
ArrayIndexConfiguration::new(QueryLanguage::N1QL, "contacts[].phones", "type");
313311

314312
assert!(default_collection
315-
.create_array_index(
316-
"myindex",
317-
&index_configuration,
318-
).unwrap()
319-
);
313+
.create_array_index("two_levels", &index_configuration,)
314+
.unwrap());
320315

321316
let query = Query::new(
322317
db,
@@ -325,18 +320,29 @@ fn array_index() {
325320
FROM _
326321
UNNEST _.contacts as contact
327322
UNNEST contact.phones as phone
328-
WHERE phone.type = 'mobile'"#
329-
).unwrap();
323+
WHERE phone.type = 'mobile'"#,
324+
)
325+
.unwrap();
330326

331327
println!("Explain: {}", query.explain().unwrap());
332328

333329
let index = get_index_name_from_explain(&query.explain().unwrap()).unwrap();
334330
assert_eq!(index, "two_levels");
335331

336332
let mut result = query.execute().unwrap();
333+
337334
let row = result.next().unwrap();
338-
assert_eq!(row.as_array().to_json(), r#"["Sam","travel"]"#);
335+
assert_eq!(
336+
row.as_array().to_json(),
337+
r#"["Sam","primary","310-123-6789"]"#
338+
);
339339

340-
assert!(result.next().is_none());*/
340+
let row = result.next().unwrap();
341+
assert_eq!(
342+
row.as_array().to_json(),
343+
r#"["Sam","secondary","206-123-6789"]"#
344+
);
345+
346+
assert!(result.next().is_none());
341347
})
342348
}

0 commit comments

Comments
 (0)