noyalib 0.0.13

A pure Rust YAML library with zero unsafe code and full serde integration
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2026 Noyalib. All rights reserved.

//! Complete coverage sweep for `src/borrowed.rs`.
//!
//! Exercises the Hash, Serialize, PartialOrd/Ord impls, the indexed /
//! wildcard / recursive branches of path queries, `into_owned` for every
//! variant, document-length enforcement, special float resolution, and
//! alias rejection on the borrowed path.

use noyalib::ParserConfig;
use noyalib::borrowed::{BorrowedValue, from_str_borrowed};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

fn hash(v: &BorrowedValue<'_>) -> u64 {
    let mut h = DefaultHasher::new();
    v.hash(&mut h);
    h.finish()
}

// ── Hash impl — every variant ────────────────────────────────────────────

#[test]
fn hash_null_is_stable() {
    let a: BorrowedValue<'_> = from_str_borrowed("~").unwrap();
    let b: BorrowedValue<'_> = from_str_borrowed("null").unwrap();
    assert_eq!(hash(&a), hash(&b));
}

#[test]
fn hash_bool() {
    let t: BorrowedValue<'_> = from_str_borrowed("true").unwrap();
    let f: BorrowedValue<'_> = from_str_borrowed("false").unwrap();
    assert_ne!(hash(&t), hash(&f));
}

#[test]
fn hash_int_vs_float() {
    let i: BorrowedValue<'_> = from_str_borrowed("42").unwrap();
    let f: BorrowedValue<'_> = from_str_borrowed("1.5").unwrap();
    assert_ne!(hash(&i), hash(&f));
}

#[test]
fn hash_string() {
    let a: BorrowedValue<'_> = from_str_borrowed("hello").unwrap();
    let b: BorrowedValue<'_> = from_str_borrowed("world").unwrap();
    assert_ne!(hash(&a), hash(&b));
}

#[test]
fn hash_sequence() {
    let s: BorrowedValue<'_> = from_str_borrowed("- 1\n- 2\n").unwrap();
    let t: BorrowedValue<'_> = from_str_borrowed("- 1\n- 2\n").unwrap();
    assert_eq!(hash(&s), hash(&t));
}

#[test]
fn hash_mapping() {
    let m: BorrowedValue<'_> = from_str_borrowed("a: 1\nb: 2\n").unwrap();
    let n: BorrowedValue<'_> = from_str_borrowed("a: 1\nb: 2\n").unwrap();
    assert_eq!(hash(&m), hash(&n));
}

#[test]
fn hash_differs_across_variants() {
    let null: BorrowedValue<'_> = from_str_borrowed("null").unwrap();
    let int: BorrowedValue<'_> = from_str_borrowed("0").unwrap();
    let bool_v: BorrowedValue<'_> = from_str_borrowed("false").unwrap();
    assert_ne!(hash(&null), hash(&int));
    assert_ne!(hash(&int), hash(&bool_v));
    assert_ne!(hash(&null), hash(&bool_v));
}

// ── Serialize — every variant ────────────────────────────────────────────

#[test]
fn serialize_null_json() {
    let v: BorrowedValue<'_> = from_str_borrowed("~").unwrap();
    assert_eq!(serde_json::to_string(&v).unwrap(), "null");
}

#[test]
fn serialize_bool_json() {
    let v: BorrowedValue<'_> = from_str_borrowed("true").unwrap();
    assert_eq!(serde_json::to_string(&v).unwrap(), "true");
}

#[test]
fn serialize_int_json() {
    let v: BorrowedValue<'_> = from_str_borrowed("42").unwrap();
    assert_eq!(serde_json::to_string(&v).unwrap(), "42");
}

#[test]
fn serialize_float_json() {
    let v: BorrowedValue<'_> = from_str_borrowed("1.5").unwrap();
    assert_eq!(serde_json::to_string(&v).unwrap(), "1.5");
}

#[test]
fn serialize_string_json() {
    let v: BorrowedValue<'_> = from_str_borrowed("hello").unwrap();
    assert_eq!(serde_json::to_string(&v).unwrap(), "\"hello\"");
}

#[test]
fn serialize_sequence_json() {
    let v: BorrowedValue<'_> = from_str_borrowed("[1, 2, 3]").unwrap();
    assert_eq!(serde_json::to_string(&v).unwrap(), "[1,2,3]");
}

#[test]
fn serialize_mapping_json() {
    let v: BorrowedValue<'_> = from_str_borrowed("a: 1\n").unwrap();
    let out = serde_json::to_string(&v).unwrap();
    assert_eq!(out, "{\"a\":1}");
}

// ── PartialOrd/Ord ───────────────────────────────────────────────────────

#[test]
fn ord_variants_rank_consistently() {
    let null: BorrowedValue<'_> = from_str_borrowed("~").unwrap();
    let bool_v: BorrowedValue<'_> = from_str_borrowed("false").unwrap();
    let int: BorrowedValue<'_> = from_str_borrowed("0").unwrap();
    let str_v: BorrowedValue<'_> = from_str_borrowed("hello").unwrap();
    let seq: BorrowedValue<'_> = from_str_borrowed("[1]").unwrap();
    let map: BorrowedValue<'_> = from_str_borrowed("a: 1\n").unwrap();
    // Rank order: Null < Bool < Number < String < Sequence < Mapping.
    assert!(null < bool_v);
    assert!(bool_v < int);
    assert!(int < str_v);
    assert!(str_v < seq);
    assert!(seq < map);
}

#[test]
fn ord_same_variant_compares_content() {
    let a: BorrowedValue<'_> = from_str_borrowed("1").unwrap();
    let b: BorrowedValue<'_> = from_str_borrowed("2").unwrap();
    assert!(a < b);

    let x: BorrowedValue<'_> = from_str_borrowed("abc").unwrap();
    let y: BorrowedValue<'_> = from_str_borrowed("xyz").unwrap();
    assert!(x < y);

    let f: BorrowedValue<'_> = from_str_borrowed("false").unwrap();
    let t: BorrowedValue<'_> = from_str_borrowed("true").unwrap();
    assert!(f < t);
}

#[test]
fn ord_equal_nulls() {
    let a: BorrowedValue<'_> = from_str_borrowed("~").unwrap();
    let b: BorrowedValue<'_> = from_str_borrowed("null").unwrap();
    assert_eq!(a.cmp(&b), core::cmp::Ordering::Equal);
}

#[test]
fn ord_sequence_by_content() {
    let a: BorrowedValue<'_> = from_str_borrowed("[1, 2]").unwrap();
    let b: BorrowedValue<'_> = from_str_borrowed("[1, 3]").unwrap();
    assert!(a < b);
}

#[test]
fn ord_mapping_by_length() {
    let a: BorrowedValue<'_> = from_str_borrowed("a: 1\n").unwrap();
    let b: BorrowedValue<'_> = from_str_borrowed("a: 1\nb: 2\n").unwrap();
    assert!(a < b);
}

#[test]
fn partial_cmp_delegates_to_cmp() {
    let a: BorrowedValue<'_> = from_str_borrowed("1").unwrap();
    let b: BorrowedValue<'_> = from_str_borrowed("2").unwrap();
    assert_eq!(a.partial_cmp(&b), Some(core::cmp::Ordering::Less));
}

// ── get_path — indexed branch ────────────────────────────────────────────

#[test]
fn get_path_index_on_sequence() {
    let v: BorrowedValue<'_> = from_str_borrowed("items:\n  - a\n  - b\n  - c\n").unwrap();
    let third = v.get_path("items[2]").expect("index hit");
    assert_eq!(third.as_str(), Some("c"));
}

#[test]
fn get_path_index_on_non_sequence_returns_none() {
    // A scalar isn't indexable — should return None without panicking.
    let v: BorrowedValue<'_> = from_str_borrowed("scalar").unwrap();
    assert!(v.get_path("[0]").is_none());
}

#[test]
fn get_path_key_on_non_mapping_returns_none() {
    let v: BorrowedValue<'_> = from_str_borrowed("[1, 2]").unwrap();
    assert!(v.get_path("foo").is_none());
}

#[test]
fn get_path_through_wildcard_returns_first_match() {
    let v: BorrowedValue<'_> = from_str_borrowed("items:\n  - a\n  - b\n").unwrap();
    // The `[*]` segment in get_path falls back to the query engine.
    let first = v.get_path("items[*]").expect("wildcard hit");
    assert_eq!(first.as_str(), Some("a"));
}

// ── into_owned — every variant ───────────────────────────────────────────

#[test]
fn into_owned_null() {
    let v: BorrowedValue<'_> = from_str_borrowed("~").unwrap();
    let owned = v.into_owned();
    assert!(owned.is_null());
}

#[test]
fn into_owned_bool() {
    let v: BorrowedValue<'_> = from_str_borrowed("false").unwrap();
    let owned = v.into_owned();
    assert_eq!(owned.as_bool(), Some(false));
}

#[test]
fn into_owned_integer() {
    let v: BorrowedValue<'_> = from_str_borrowed("42").unwrap();
    let owned = v.into_owned();
    assert_eq!(owned.as_i64(), Some(42));
}

#[test]
fn into_owned_float() {
    let v: BorrowedValue<'_> = from_str_borrowed("2.5").unwrap();
    let owned = v.into_owned();
    assert!((owned.as_f64().unwrap() - 2.5).abs() < 1e-9);
}

#[test]
fn into_owned_string() {
    let v: BorrowedValue<'_> = from_str_borrowed("hello").unwrap();
    let owned = v.into_owned();
    assert_eq!(owned.as_str(), Some("hello"));
}

#[test]
fn into_owned_sequence_with_mixed_types() {
    let v: BorrowedValue<'_> = from_str_borrowed("- 1\n- a\n- true\n").unwrap();
    let owned = v.into_owned();
    let seq = owned.as_sequence().expect("seq");
    assert_eq!(seq[0].as_i64(), Some(1));
    assert_eq!(seq[1].as_str(), Some("a"));
    assert_eq!(seq[2].as_bool(), Some(true));
}

// ── Query engine: wildcard / recursive / mapping traversal ──────────────

#[test]
fn query_wildcard_on_mapping_iterates_values() {
    let v: BorrowedValue<'_> = from_str_borrowed("{a: 1, b: 2, c: 3}").unwrap();
    let results = v.query("*");
    // Wildcard on a mapping yields the values in insertion order.
    assert_eq!(results.len(), 3);
}

#[test]
fn query_recursive_descent_with_key_target() {
    // `..key` recurses through all nested containers looking for `key`.
    let yaml = "a:\n  b:\n    target: found1\n  c:\n    target: found2\n";
    let v: BorrowedValue<'_> = from_str_borrowed(yaml).unwrap();
    let results = v.query("..target");
    assert!(
        results.len() >= 2,
        "expected at least 2 hits, got {}",
        results.len()
    );
}

#[test]
fn query_chained_segments_through_mapping_and_sequence() {
    let yaml =
        "users:\n  - name: alice\n    roles: [admin, user]\n  - name: bob\n    roles: [user]\n";
    let v: BorrowedValue<'_> = from_str_borrowed(yaml).unwrap();
    let results = v.query("users[*].roles[0]");
    // Each user's first role.
    assert_eq!(results.len(), 2);
    assert_eq!(results[0].as_str(), Some("admin"));
    assert_eq!(results[1].as_str(), Some("user"));
}

// ── Document length limit ────────────────────────────────────────────────

#[test]
fn from_str_borrowed_uses_default_config() {
    // Ensure the default config permits a modestly sized input.
    let yaml = "a: 1\n".repeat(100);
    let _ = from_str_borrowed(&yaml).unwrap();
}

// The ParserConfig-bound variant is not currently public; the borrowed
// module hard-codes limits, so the document-length guard is exercised
// implicitly via `from_str_borrowed` when the input is huge. Skipping
// the direct test to avoid allocating ~64MB of YAML.

// ── Special float resolution in borrowed path ────────────────────────────

#[test]
fn borrowed_parses_positive_infinity() {
    let v: BorrowedValue<'_> = from_str_borrowed(".inf").unwrap();
    // BorrowedValue exposes floats via its Number variant — as_str is None.
    assert_eq!(v.as_str(), None);
}

#[test]
fn borrowed_parses_negative_infinity() {
    let v: BorrowedValue<'_> = from_str_borrowed("-.inf").unwrap();
    assert_eq!(v.as_str(), None);
}

#[test]
fn borrowed_parses_nan() {
    let v: BorrowedValue<'_> = from_str_borrowed(".nan").unwrap();
    assert_eq!(v.as_str(), None);
}

// ── Aliases are eagerly resolved on the borrowed path ───────────────────

#[test]
fn borrowed_resolves_simple_alias() {
    // Anchors and aliases are now resolved on the borrowed path —
    // the alias clones the anchored value into the tree.
    let yaml = "anchor: &a hello\nalias: *a\n";
    let v: BorrowedValue<'_> = from_str_borrowed(yaml).unwrap();
    let map = v.as_mapping().expect("top-level must be a mapping");
    assert_eq!(map.get("anchor").and_then(|v| v.as_str()), Some("hello"));
    assert_eq!(map.get("alias").and_then(|v| v.as_str()), Some("hello"));
}

// ── Round-trip equivalence with owned path ──────────────────────────────

#[test]
fn borrowed_into_owned_matches_from_str() {
    let yaml = "name: app\nversion: 1.2.3\nfeatures:\n  - auth\n  - api\n";
    let borrowed: BorrowedValue<'_> = from_str_borrowed(yaml).unwrap();
    let via_borrowed = borrowed.into_owned();
    let via_owned: noyalib::Value = noyalib::from_str(yaml).unwrap();
    assert_eq!(via_borrowed, via_owned);
}

// ── Depth / size limits hit the error paths ─────────────────────────────

#[test]
fn deeply_nested_borrowed_errors() {
    // from_str_borrowed uses its own default config. A document that
    // exceeds any sensible recursion depth should still return a
    // meaningful error rather than crash.
    let mut yaml = String::new();
    for _ in 0..500 {
        yaml.push_str("a:\n  ");
    }
    yaml.push_str("stop");
    let result = from_str_borrowed(&yaml);
    // Depending on the depth limit, either parses or errors — both are
    // acceptable; the key invariant is no crash.
    let _ = result;
}

// ── ParserConfig-style boundary check through from_str (equivalence) ────

#[test]
fn document_length_limit_checked_by_owned_side() {
    // Exercised via the owned path, but included here so the
    // corresponding code path in borrowed.rs sees traffic.
    let config = ParserConfig::new().max_document_length(10);
    let yaml = "this string is way too long for the document limit";
    assert!(noyalib::from_str_with_config::<noyalib::Value>(yaml, &config).is_err());
}

// ── Recursive-descent query through sequences and mappings ──────────────

#[test]
fn query_recursive_sequence_traversal() {
    // ..name should match `name` at every depth
    let yaml = "users:\n  - name: alice\n  - name: bob\nadmins:\n  - name: root\n";
    let v: BorrowedValue<'_> = from_str_borrowed(yaml).unwrap();
    let results = v.query("..name");
    assert!(results.len() >= 3);
}

#[test]
fn query_recursive_through_nested_sequences() {
    let yaml = "a:\n  - b:\n    - c: found\n";
    let v: BorrowedValue<'_> = from_str_borrowed(yaml).unwrap();
    let results = v.query("..c");
    assert!(!results.is_empty());
    assert_eq!(results[0].as_str(), Some("found"));
}

#[test]
fn query_recursive_on_scalar_returns_nothing() {
    let v: BorrowedValue<'_> = from_str_borrowed("42").unwrap();
    let results = v.query("..any_key");
    // Recursive descent into a scalar yields no results.
    assert!(results.is_empty());
}

#[test]
fn query_wildcard_on_scalar_returns_empty() {
    let v: BorrowedValue<'_> = from_str_borrowed("42").unwrap();
    let results = v.query("*");
    // Wildcard on scalar → nothing.
    assert!(results.is_empty());
}

// ── Tagged scalars (force the "return BorrowedValue::String" branch) ─────

#[test]
fn borrowed_tagged_scalar_is_accepted() {
    // Tags force the "early return as String" branch in resolve_scalar.
    // The borrowed path preserves the raw text (may or may not include
    // the tag); the key invariant is no crash.
    let v: BorrowedValue<'_> = from_str_borrowed("!!str 42").unwrap();
    // Result is either a string or number depending on tag handling —
    // both are acceptable, neither panics.
    let _ = v;
}

#[test]
fn borrowed_custom_tag_is_accepted() {
    let v: BorrowedValue<'_> = from_str_borrowed("!mytag hello").unwrap();
    let _ = v;
}

// ── Recursion / end-of-sequence / end-of-mapping error paths ────────────

#[test]
fn deep_borrowed_sequence_may_error() {
    let mut yaml = String::new();
    for _ in 0..200 {
        yaml.push_str("- ");
    }
    yaml.push_str("deep");
    // This may parse or error — key is no panic.
    let _ = from_str_borrowed(&yaml);
}

#[test]
fn deep_borrowed_mapping_may_error() {
    let mut yaml = String::new();
    for _ in 0..200 {
        yaml.push_str("a:\n  ");
    }
    yaml.push_str("done");
    let _ = from_str_borrowed(&yaml);
}

// ── Quoted / non-plain scalars take the fast-path String branch ─────────

#[test]
fn borrowed_double_quoted_scalar() {
    let v: BorrowedValue<'_> = from_str_borrowed("\"hello world\"").unwrap();
    assert_eq!(v.as_str(), Some("hello world"));
}

#[test]
fn borrowed_single_quoted_numeric_stays_string() {
    let v: BorrowedValue<'_> = from_str_borrowed("'42'").unwrap();
    assert_eq!(v.as_str(), Some("42"));
    assert_eq!(v.as_i64(), None);
}

#[test]
fn borrowed_literal_block_scalar() {
    let yaml = "key: |\n  line1\n  line2\n";
    let v: BorrowedValue<'_> = from_str_borrowed(yaml).unwrap();
    let k = v.as_mapping().unwrap().get("key").unwrap();
    assert!(k.as_str().is_some());
}

#[test]
fn borrowed_folded_block_scalar() {
    let yaml = "key: >\n  folded text\n";
    let v: BorrowedValue<'_> = from_str_borrowed(yaml).unwrap();
    let k = v.as_mapping().unwrap().get("key").unwrap();
    assert!(k.as_str().is_some());
}

// ── Recursive descent "continue" branches ───────────────────────────────

#[test]
fn query_recursive_descent_on_empty_mapping() {
    let v: BorrowedValue<'_> = from_str_borrowed("{}").unwrap();
    let results = v.query("..anything");
    assert!(results.is_empty());
}

#[test]
fn query_recursive_descent_on_empty_sequence() {
    let v: BorrowedValue<'_> = from_str_borrowed("[]").unwrap();
    let results = v.query("..anything");
    assert!(results.is_empty());
}

// ── Hit the recursion-limit branches in the borrowed path ──────────────

#[test]
fn borrowed_sequence_past_depth_limit_errors() {
    // Default max_depth is 128; 130-level nested sequence exceeds it.
    let mut yaml = String::new();
    for _ in 0..130 {
        yaml.push_str("- ");
    }
    yaml.push_str("deep");
    let result = from_str_borrowed(&yaml);
    // Either errors with recursion limit, or the parser itself errors
    // — both paths exercise the same uncovered branch.
    assert!(result.is_err());
}

#[test]
fn borrowed_mapping_past_depth_limit_errors() {
    let mut yaml = String::new();
    for _ in 0..130 {
        yaml.push_str("a:\n  ");
    }
    yaml.push_str("stop");
    let result = from_str_borrowed(&yaml);
    assert!(result.is_err());
}

// ── Query recursive descent branch variations ─────────────────────────

#[test]
fn query_recursive_descent_into_sequence_inner() {
    // The "BorrowedValue::Sequence(seq) for item in seq" recursive branch
    // is hit when descending into sequences — exercises line ~300.
    let yaml = "top:\n  - key: found\n  - other: x\n";
    let v: BorrowedValue<'_> = from_str_borrowed(yaml).unwrap();
    let results = v.query("..key");
    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_str(), Some("found"));
}

// ── Recursive descent followed by index ─────────────────────────────────

#[test]
fn query_recursive_descent_with_index_target() {
    let yaml = "a:\n  items:\n    - first\n    - second\nb:\n  items:\n    - x\n    - y\n";
    let v: BorrowedValue<'_> = from_str_borrowed(yaml).unwrap();
    // `..items[0]` → descend until we find `items`, then take [0].
    let results = v.query("..items[0]");
    assert!(results.len() >= 2);
}

#[test]
fn query_recursive_descent_at_end_is_noop() {
    // A path that is just `..` and nothing else is a no-op — the
    // recursive-descent close-brace (line 310) is hit when
    // `remaining.is_empty()`.
    let v: BorrowedValue<'_> = from_str_borrowed("a: 1\n").unwrap();
    let results = v.query("..");
    // Implementation-defined; we just exercise the branch without panic.
    let _ = results;
}

// ── Numeric-looking plain scalar that doesn't parse as number ──────────

#[test]
fn numeric_prefix_but_not_a_number_becomes_string() {
    // "-abc" — starts with `-` so takes the numeric-attempt branch,
    // fails both i64 and f64 parse, falls through to String.
    let v: BorrowedValue<'_> = from_str_borrowed("-abc").unwrap();
    assert_eq!(v.as_str(), Some("-abc"));
}

#[test]
fn dot_prefix_non_numeric_stays_string() {
    let v: BorrowedValue<'_> = from_str_borrowed(".dotfile").unwrap();
    assert_eq!(v.as_str(), Some(".dotfile"));
}

// ── Document-length check via config ────────────────────────────────────

#[test]
fn borrowed_document_length_limit_enforced() {
    use noyalib::borrowed::from_str_borrowed_with_config;
    let config = ParserConfig::new().max_document_length(10);
    let yaml = "this yaml is way longer than ten bytes";
    let err = from_str_borrowed_with_config(yaml, &config).unwrap_err();
    assert!(err.to_string().contains("maximum length"));
}

#[test]
fn borrowed_tight_depth_limit_errors_on_nesting() {
    use noyalib::borrowed::from_str_borrowed_with_config;
    let config = ParserConfig::new().max_depth(2);
    let yaml = "- - - - deeper\n";
    let result = from_str_borrowed_with_config(yaml, &config);
    assert!(result.is_err());
}

#[test]
fn borrowed_with_config_same_as_default() {
    use noyalib::borrowed::from_str_borrowed_with_config;
    let yaml = "k: v\n";
    let default = ParserConfig::new();
    let v = from_str_borrowed_with_config(yaml, &default).unwrap();
    let v2 = from_str_borrowed(yaml).unwrap();
    assert_eq!(v.into_owned(), v2.into_owned());
}