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
// Shared fixtures and helpers for WASM integration tests.
use JsCast;
use *;
// =============================================================================
// Test Fixtures — CSV data embedded at compile time
// =============================================================================
//
// These are CSV test files from the shared test-fixtures directory. They're
// compiled INTO the test binary, so no filesystem access is needed at
// runtime. `include_bytes!()` reads a file at compile time and returns
// a `&[u8]` (byte slice) — like a hardcoded array of bytes.
/// A simple, clean CSV with 3 columns and 5 data rows.
/// No whitespace issues, no empty rows, no duplicates.
/// Used as a baseline "nothing to clean" test case.
pub const SIMPLE_CSV: & = include_bytes!;
/// A messy CSV with whitespace, empty rows, and duplicates.
/// This is the "kitchen sink" test case that exercises all
/// cleaning operations at once.
pub const MESSY_CSV: & = include_bytes!;
/// A CSV with only a header row and no data.
/// Edge case: should return the header with zero data rows.
pub const HEADERS_ONLY_CSV: & =
include_bytes!;
/// A CSV with many columns (8) for rename-columns testing.
/// Has first_name, last_name, email, phone, city, state, zip, department.
pub const MANY_COLUMNS_CSV: & =
include_bytes!;
// =============================================================================
// Inline Test Fixtures — For quick, specific test cases
// =============================================================================
/// Minimal 3-column CSV for rename-columns tests.
/// "name", "age", "city" — easy to verify column renames on.
pub const MINIMAL_CSV: & = b"name,age,city\nAlice,30,NYC\nBob,25,LA\n";
/// Simple CSV as raw bytes (for tests that don't need file fixtures).
pub const CSV_WITH_EMPTY_ROWS: & = b"name,age\nAlice,30\n,,\nBob,25\n,,\n";
/// CSV with exact duplicate rows.
pub const CSV_WITH_DUPLICATES: & = b"name,age\nAlice,30\nBob,25\nAlice,30\n";
/// CSV with whitespace around cell values.
pub const CSV_WITH_WHITESPACE: & = b"name,age\n Alice , 30 \n Bob ,25\n";
// =============================================================================
// Helper Functions
// =============================================================================
/// Create a JavaScript function that does nothing (for progress callbacks).
///
/// Most tests don't care about progress reporting — they just need a
/// valid callback to pass to the WASM functions. This creates a JS
/// `function() {}` that accepts any arguments and does nothing.
/// Create a JavaScript callback that records every (percent, message) call.
///
/// Returns `(callback_function, calls_array)`. Inspect `calls_array`
/// after processing to verify progress updates.
// =============================================================================
// Combined Result Extraction Helpers
// =============================================================================
//
// The combined WASM functions (clean_csv_combined, rename_csv_columns_combined)
// return a single JsValue that is a JS object with four properties:
// - metadata: JSON string with processing stats (rows removed, columns renamed, etc.)
// - data: Uint8Array containing the raw output CSV bytes
// - filename: string with the suggested output filename
// - mimeType: string with the MIME type (always "text/csv" for CSV)
//
// These helpers extract each property from the combined result so individual
// tests can inspect whichever part they care about.
/// Extract metadata JSON string from a combined function result.
///
/// The metadata is a JSON string containing processing statistics like
/// rowsRemoved, duplicatesRemoved, columnsRenamed, etc. Tests can parse
/// this string to verify that the right operations were applied.
/// Extract raw bytes from a combined function result.
///
/// The data property is a Uint8Array in JS land. We convert it to a
/// Vec<u8> so Rust tests can work with it as normal bytes — parsing
/// as UTF-8, checking content, etc.
/// Extract output filename from a combined function result.
///
/// The filename is a suggested name for the output file, e.g.
/// "data-cleaned.csv" or "test-renamed.csv". Tests verify that
/// the naming convention is applied correctly.
/// Extract MIME type from a combined function result.
///
/// Returns the MIME type string for the output file, e.g.,
/// "text/csv" for CSV operations.
/// Initialize panic hook for test reliability.
///
/// In production, the bnto-wasm entry point handles this. In these
/// integration tests, the bnto-wasm entry point isn't loaded, so we
/// skip the panic hook — errors will still show in the test output,
/// just without the pretty console.error formatting.