mod_interface_meta 0.59.0

Protocol of modularity unifying interface of a module and introducing layers.
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
//! Corner Case Tests for `mod_interface_meta`
//!
//! This test suite systematically validates corner cases and edge cases in the
//! `mod_interface` procedural macro implementation. Tests are organized by
//! category and cover use statement variations, layer directives, micro-modules,
//! visibility propagation, and error conditions.

// =============================================================================
// Phase 1: Use Statement Variations
// =============================================================================

/// UC-01: Simple identifier with own layer
/// Tests that `` `own use` `` exports to own layer only (not orphan/exposed/prelude).
/// Items in `own_clause` are accessible via `own::` and root; the cascade runs
/// prelude → exposed → orphan → own, so own items do not propagate downward.
mod uc_01_own_use_simple
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn my_fn() -> bool { true }
  }

  mod_interface!
  {
    own use my_fn;
  }

  #[ test ]
  fn own_layer_has_item()
  {
    assert!( own::my_fn() );
  }
}

/// UC-02: Simple identifier with orphan layer
/// Tests that `` `orphan use` `` exports to orphan+own layers (not exposed/prelude).
/// Items in `orphan_clause` are accessible via `orphan::`, `own::`, and root.
mod uc_02_orphan_use_simple
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn my_fn() -> bool { true }
  }

  mod_interface!
  {
    orphan use my_fn;
  }

  #[ test ]
  fn orphan_layer_has_item()
  {
    assert!( orphan::my_fn() );
  }

  #[ test ]
  fn own_layer_has_item()
  {
    assert!( own::my_fn() );
  }
}

/// UC-03: Simple identifier with exposed layer
/// Tests that `` `exposed use` `` exports to exposed+orphan+own layers (not prelude).
/// Items in `exposed_clause` are accessible via `exposed::`, `orphan::`, `own::`, and root.
mod uc_03_exposed_use_simple
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn my_fn() -> bool { true }
  }

  mod_interface!
  {
    exposed use my_fn;
  }

  #[ test ]
  fn exposed_layer_has_item()
  {
    assert!( exposed::my_fn() );
  }

  #[ test ]
  fn orphan_layer_has_item()
  {
    assert!( orphan::my_fn() );
  }

  #[ test ]
  fn own_layer_has_item()
  {
    assert!( own::my_fn() );
  }
}

/// UC-04: Simple identifier with prelude layer
/// Tests that `prelude use` exports only to prelude layer
mod uc_04_prelude_use_simple
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn my_fn() -> bool { true }
  }

  mod_interface!
  {
    prelude use my_fn;
  }

  #[ test ]
  fn prelude_layer_has_item()
  {
    assert!( prelude::my_fn() );
  }
}

/// UC-05: Implicit use (no layer keyword)
/// Tests that bare `use` exports to all layers
mod uc_05_implicit_use_all_layers
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn my_fn() -> bool { true }
  }

  mod_interface!
  {
    use my_fn;
  }

  #[ test ]
  fn own_layer_has_item()
  {
    assert!( own::my_fn() );
  }

  #[ test ]
  fn orphan_layer_has_item()
  {
    assert!( orphan::my_fn() );
  }

  #[ test ]
  fn exposed_layer_has_item()
  {
    assert!( exposed::my_fn() );
  }

  #[ test ]
  fn prelude_layer_has_item()
  {
    assert!( prelude::my_fn() );
  }
}

/// UC-09: Rename with as keyword
/// Tests that `use Type1 as Alias` works correctly
mod uc_09_use_with_rename
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn original_name() -> bool { true }
  }

  mod_interface!
  {
    own use original_name as aliased_name;
  }

  #[ test ]
  fn aliased_name_works()
  {
    assert!( own::aliased_name() );
  }
}

/// UC-13: Multiple use statements in same layer
/// Tests that multiple `own use` statements work correctly
mod uc_13_multiple_use_statements
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn fn_a() -> bool { true }
    pub fn fn_b() -> bool { true }
    pub fn fn_c() -> bool { true }
  }

  mod_interface!
  {
    own use fn_a;
    own use fn_b;
    own use fn_c;
  }

  #[ test ]
  fn all_functions_exported()
  {
    assert!( own::fn_a() );
    assert!( own::fn_b() );
    assert!( own::fn_c() );
  }
}

/// UC-14: Mixed implicit and explicit use statements
/// Tests that `use` and `own use` can coexist
mod uc_14_mixed_implicit_explicit
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn implicit_fn() -> bool { true }
    pub fn explicit_fn() -> bool { true }
  }

  mod_interface!
  {
    use implicit_fn;
    own use explicit_fn;
  }

  #[ test ]
  fn implicit_in_all_layers()
  {
    assert!( own::implicit_fn() );
    assert!( orphan::implicit_fn() );
    assert!( exposed::implicit_fn() );
    assert!( prelude::implicit_fn() );
  }

  #[ test ]
  fn explicit_in_own_layer_only()
  {
    // `own use explicit_fn` → own_clause → accessible in own:: and root only
    assert!( own::explicit_fn() );
  }
}

// =============================================================================
// Phase 3: Micro-Module Variations
// =============================================================================

/// MM-01 through MM-04: All four micro-module types
/// Tests that micro-modules work in all four layers
mod mm_01_04_micro_modules_all_layers
{
  use mod_interface_meta::mod_interface;

  mod private {}

  mod_interface!
  {
    own mod micro_own;
    orphan mod micro_orphan;
    exposed mod micro_exposed;
    prelude mod micro_prelude;
  }

  #[ test ]
  fn all_micro_modules_exist()
  {
    // Verify modules are created (compile-time check)
    let _ = micro_own::has_marker();
    let _ = micro_orphan::has_marker();
    let _ = micro_exposed::has_marker();
    let _ = micro_prelude::has_marker();
  }
}

/// MM-07: Multiple micro-modules in same layer
/// Tests that multiple micro-modules in one layer work correctly
mod mm_07_multiple_micro_modules_same_layer
{
  use mod_interface_meta::mod_interface;

  mod private {}

  mod_interface!
  {
    own mod mod_a;
    own mod mod_b;
    own mod mod_c;
  }

  #[ test ]
  fn all_modules_created()
  {
    // Compile-time verification
    let _ = mod_a::marker();
    let _ = mod_b::marker();
    let _ = mod_c::marker();
  }
}

// =============================================================================
// Phase 5: Namespace Combinations
// =============================================================================

/// NC-06: Only own layer populated
/// Tests that populating only own layer works correctly
mod nc_06_only_own_populated
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn own_fn() -> bool { true }
  }

  mod_interface!
  {
    own use own_fn;
  }

  #[ test ]
  fn own_has_content()
  {
    // own_clause items are accessible via own:: and root; cascade does not propagate them down
    assert!( own::own_fn() );
  }
}

/// NC-07: Only prelude layer populated
/// Tests that populating only prelude works correctly
mod nc_07_only_prelude_populated
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn prelude_fn() -> bool { true }
  }

  mod_interface!
  {
    prelude use prelude_fn;
  }

  #[ test ]
  fn prelude_has_content()
  {
    assert!( prelude::prelude_fn() );
  }
}

// =============================================================================
// Phase 9: Integration Patterns
// =============================================================================

/// IP-01: Mix all item types
/// Tests that structs, traits, functions, and constants all work
mod ip_01_mix_all_item_types
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub struct MyStruct;
    pub trait MyTrait {}
    pub fn my_fn() -> bool { true }
    pub const MY_CONST : i32 = 42;
  }

  mod_interface!
  {
    own use MyStruct;
    orphan use MyTrait;
    exposed use my_fn;
    prelude use MY_CONST;
  }

  #[ test ]
  fn struct_exported()
  {
    let _ : own::MyStruct = own::MyStruct;
  }

  #[ test ]
  fn trait_exported()
  {
    // Compile-time check that trait is accessible
    // Define a type that implements the trait
    struct TestType;
    impl orphan::MyTrait for TestType {}

    // Verify we can use the trait bound
    fn check_trait<T : orphan::MyTrait>(_: T) {}
    check_trait(TestType);
  }

  #[ test ]
  fn function_exported()
  {
    assert!( exposed::my_fn() );
  }

  #[ test ]
  fn const_exported()
  {
    assert_eq!( prelude::MY_CONST, 42 );
  }
}

/// IP-03: Empty private namespace
/// Tests whether empty private namespace is allowed
mod ip_03_empty_private_namespace
{
  use mod_interface_meta::mod_interface;

  mod private {}

  mod_interface!
  {
    // No items
  }

  #[ test ]
  fn compiles_successfully()
  {
    // Compile-time verification
  }
}

/// IP-04: Private namespace with content
/// Tests that content in private namespace doesn't interfere
mod ip_04_private_with_content
{
  use mod_interface_meta::mod_interface;

  mod private
  {
    pub fn exposed_fn() -> bool { true }
    pub fn hidden_fn() -> bool { true }
  }

  mod_interface!
  {
    own use exposed_fn;
    // hidden_fn is not re-exported
  }

  #[ test ]
  fn exposed_fn_accessible()
  {
    assert!( own::exposed_fn() );
  }

  #[ test ]
  fn hidden_fn_not_in_public_interface()
  {
    // hidden_fn is accessible via private::hidden_fn() but not via layers
    assert!( private::hidden_fn() );
  }
}