diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..85a5c31
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+internal/diff/diff.go linguist-vendored
diff --git a/__snapshots__/test_complex_j_s_o_n_structure.snap b/__snapshots__/test_complex_json_structure.snap
similarity index 98%
rename from __snapshots__/test_complex_j_s_o_n_structure.snap
rename to __snapshots__/test_complex_json_structure.snap
index ca9333f..23d79e8 100644
--- a/__snapshots__/test_complex_j_s_o_n_structure.snap
+++ b/__snapshots__/test_complex_json_structure.snap
@@ -1,6 +1,6 @@
---
title: Complex JSON Structure
-test_name: TestComplexJSONStructure
+test_name: TestComplexJsonStructure
file_path:
func_name:
version: 0.1.0
diff --git a/__snapshots__/test_deeply_nested_j_s_o_n.snap b/__snapshots__/test_deeply_nested_json.snap
similarity index 88%
rename from __snapshots__/test_deeply_nested_j_s_o_n.snap
rename to __snapshots__/test_deeply_nested_json.snap
index 71b8853..646acb0 100644
--- a/__snapshots__/test_deeply_nested_j_s_o_n.snap
+++ b/__snapshots__/test_deeply_nested_json.snap
@@ -1,6 +1,6 @@
---
title: Deeply Nested JSON
-test_name: TestDeeplyNestedJSON
+test_name: TestDeeplyNestedJson
file_path:
func_name:
version: 0.1.0
diff --git a/__snapshots__/test_go_struct_marshalled_to_j_s_o_n.snap b/__snapshots__/test_go_struct_marshalled_to_json.snap
similarity index 91%
rename from __snapshots__/test_go_struct_marshalled_to_j_s_o_n.snap
rename to __snapshots__/test_go_struct_marshalled_to_json.snap
index e96d1f9..525d3f8 100644
--- a/__snapshots__/test_go_struct_marshalled_to_j_s_o_n.snap
+++ b/__snapshots__/test_go_struct_marshalled_to_json.snap
@@ -1,6 +1,6 @@
---
title: Go Struct Marshalled to JSON
-test_name: TestGoStructMarshalledToJSON
+test_name: TestGoStructMarshalledToJson
file_path:
func_name:
version: 0.1.0
diff --git a/__snapshots__/test_j_s_o_n_array_of_objects.snap b/__snapshots__/test_json_array_of_objects.snap
similarity index 94%
rename from __snapshots__/test_j_s_o_n_array_of_objects.snap
rename to __snapshots__/test_json_array_of_objects.snap
index 756c0ce..f09a17b 100644
--- a/__snapshots__/test_j_s_o_n_array_of_objects.snap
+++ b/__snapshots__/test_json_array_of_objects.snap
@@ -1,6 +1,6 @@
---
title: JSON Array of Objects
-test_name: TestJSONArrayOfObjects
+test_name: TestJsonArrayOfObjects
file_path:
func_name:
version: 0.1.0
diff --git a/__snapshots__/test_j_s_o_n_numbers.snap b/__snapshots__/test_json_numbers.snap
similarity index 94%
rename from __snapshots__/test_j_s_o_n_numbers.snap
rename to __snapshots__/test_json_numbers.snap
index 42f3bc2..97a05fb 100644
--- a/__snapshots__/test_j_s_o_n_numbers.snap
+++ b/__snapshots__/test_json_numbers.snap
@@ -1,6 +1,6 @@
---
title: JSON Numbers
-test_name: TestJSONNumbers
+test_name: TestJsonNumbers
file_path:
func_name:
version: 0.1.0
diff --git a/__snapshots__/test_j_s_o_n_object.snap b/__snapshots__/test_json_object.snap
similarity index 94%
rename from __snapshots__/test_j_s_o_n_object.snap
rename to __snapshots__/test_json_object.snap
index be50307..686d602 100644
--- a/__snapshots__/test_j_s_o_n_object.snap
+++ b/__snapshots__/test_json_object.snap
@@ -1,6 +1,6 @@
---
title: JSON Object
-test_name: TestJSONObject
+test_name: TestJsonObject
file_path:
func_name:
version: 0.1.0
diff --git a/__snapshots__/test_j_s_o_n_with_mixed_arrays.snap b/__snapshots__/test_json_with_mixed_arrays.snap
similarity index 95%
rename from __snapshots__/test_j_s_o_n_with_mixed_arrays.snap
rename to __snapshots__/test_json_with_mixed_arrays.snap
index 30d1f6f..87c6b65 100644
--- a/__snapshots__/test_j_s_o_n_with_mixed_arrays.snap
+++ b/__snapshots__/test_json_with_mixed_arrays.snap
@@ -1,6 +1,6 @@
---
title: JSON with Mixed Arrays
-test_name: TestJSONWithMixedArrays
+test_name: TestJsonWithMixedArrays
file_path:
func_name:
version: 0.1.0
diff --git a/__snapshots__/test_j_s_o_n_with_special_characters.snap b/__snapshots__/test_json_with_special_characters.snap
similarity index 91%
rename from __snapshots__/test_j_s_o_n_with_special_characters.snap
rename to __snapshots__/test_json_with_special_characters.snap
index 92d21bb..ab98415 100644
--- a/__snapshots__/test_j_s_o_n_with_special_characters.snap
+++ b/__snapshots__/test_json_with_special_characters.snap
@@ -1,6 +1,6 @@
---
title: JSON with Special Characters
-test_name: TestJSONWithSpecialCharacters
+test_name: TestJsonWithSpecialCharacters
file_path:
func_name:
version: 0.1.0
diff --git a/__snapshots__/test_j_s_o_n_with_various_types.snap b/__snapshots__/test_json_with_various_types.snap
similarity index 93%
rename from __snapshots__/test_j_s_o_n_with_various_types.snap
rename to __snapshots__/test_json_with_various_types.snap
index 1271969..c0f82c8 100644
--- a/__snapshots__/test_j_s_o_n_with_various_types.snap
+++ b/__snapshots__/test_json_with_various_types.snap
@@ -1,6 +1,6 @@
---
title: JSON with Various Types
-test_name: TestJSONWithVariousTypes
+test_name: TestJsonWithVariousTypes
file_path:
func_name:
version: 0.1.0
diff --git a/__snapshots__/test_large_j_s_o_n.snap b/__snapshots__/test_large_json.snap
similarity index 97%
rename from __snapshots__/test_large_j_s_o_n.snap
rename to __snapshots__/test_large_json.snap
index 2a3c3a9..3a15e32 100644
--- a/__snapshots__/test_large_j_s_o_n.snap
+++ b/__snapshots__/test_large_json.snap
@@ -1,6 +1,6 @@
---
title: Large JSON Structure
-test_name: TestLargeJSON
+test_name: TestLargeJson
file_path:
func_name:
version: 0.1.0
diff --git a/__snapshots__/test_snap_j_s_o_n_array_of_objects.snap b/__snapshots__/test_snap_j_s_o_n_array_of_objects.snap
deleted file mode 100644
index 0d01768..0000000
--- a/__snapshots__/test_snap_j_s_o_n_array_of_objects.snap
+++ /dev/null
@@ -1,30 +0,0 @@
----
-title: SnapJSON Array of Objects
-test_name: TestSnapJSONArrayOfObjects
-file_path:
-func_name:
-version: 0.1.0
----
-[]interface{}{
- map[string]interface{}{
- "id": 1.0,
- "likes": 42.0,
- "title": "First Post",
- "type": "post",
- "views": 150.0,
- },
- map[string]interface{}{
- "id": 2.0,
- "likes": 75.0,
- "title": "Second Post",
- "type": "post",
- "views": 280.0,
- },
- map[string]interface{}{
- "id": 3.0,
- "likes": 120.0,
- "title": "Third Post",
- "type": "post",
- "views": 450.0,
- },
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_basic.snap b/__snapshots__/test_snap_j_s_o_n_basic.snap
deleted file mode 100644
index c070c54..0000000
--- a/__snapshots__/test_snap_j_s_o_n_basic.snap
+++ /dev/null
@@ -1,13 +0,0 @@
----
-title: SnapJSON Basic Object
-test_name: TestSnapJSONBasic
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "age": 30.0,
- "email": "john@example.com",
- "name": "John Doe",
- "verified": true,
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_compact_format.snap b/__snapshots__/test_snap_j_s_o_n_compact_format.snap
deleted file mode 100644
index 2e7b4c5..0000000
--- a/__snapshots__/test_snap_j_s_o_n_compact_format.snap
+++ /dev/null
@@ -1,17 +0,0 @@
----
-title: SnapJSON Compact Format
-test_name: TestSnapJSONCompactFormat
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "id": 1.0,
- "in_stock": true,
- "name": "Product",
- "price": 99.99,
- "tags": []interface{}{
- "electronics",
- "gadgets",
- },
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_complex_a_p_i.snap b/__snapshots__/test_snap_j_s_o_n_complex_a_p_i.snap
deleted file mode 100644
index 01f27fc..0000000
--- a/__snapshots__/test_snap_j_s_o_n_complex_a_p_i.snap
+++ /dev/null
@@ -1,43 +0,0 @@
----
-title: SnapJSON Complex API Response
-test_name: TestSnapJSONComplexAPI
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "code": 200.0,
- "data": map[string]interface{}{
- "pagination": map[string]interface{}{
- "page": 1.0,
- "per_page": 10.0,
- "total": 3.0,
- "total_pages": 1.0,
- },
- "users": []interface{}{
- map[string]interface{}{
- "active": true,
- "department": "Engineering",
- "id": 1.0,
- "name": "Alice",
- "role": "admin",
- },
- map[string]interface{}{
- "active": true,
- "department": "Sales",
- "id": 2.0,
- "name": "Bob",
- "role": "user",
- },
- map[string]interface{}{
- "active": false,
- "department": "Marketing",
- "id": 3.0,
- "name": "Charlie",
- "role": "user",
- },
- },
- },
- "status": "success",
- "timestamp": "2023-11-18T21:45:30Z",
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_empty_structures.snap b/__snapshots__/test_snap_j_s_o_n_empty_structures.snap
deleted file mode 100644
index af8f254..0000000
--- a/__snapshots__/test_snap_j_s_o_n_empty_structures.snap
+++ /dev/null
@@ -1,23 +0,0 @@
----
-title: SnapJSON Empty Structures
-test_name: TestSnapJSONEmptyStructures
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "empty_array": []interface{}{
- },
- "empty_object": map[string]interface{}{
- },
- "empty_string": "",
- "false_value": false,
- "nested": map[string]interface{}{
- "also_empty": map[string]interface{}{
- },
- "empty": []interface{}{
- },
- },
- "null_value": nil,
- "zero": 0.0,
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_large_nested_structure.snap b/__snapshots__/test_snap_j_s_o_n_large_nested_structure.snap
deleted file mode 100644
index e2fe139..0000000
--- a/__snapshots__/test_snap_j_s_o_n_large_nested_structure.snap
+++ /dev/null
@@ -1,105 +0,0 @@
----
-title: SnapJSON Large Nested Structure
-test_name: TestSnapJSONLargeNestedStructure
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "organization": map[string]interface{}{
- "departments": []interface{}{
- map[string]interface{}{
- "manager": "Alice",
- "name": "Engineering",
- "teams": []interface{}{
- map[string]interface{}{
- "lead": "John",
- "members": []interface{}{
- map[string]interface{}{
- "id": 1.0,
- "level": "senior",
- "name": "John",
- },
- map[string]interface{}{
- "id": 2.0,
- "level": "mid",
- "name": "Jane",
- },
- },
- "name": "Backend",
- "projects": []interface{}{
- map[string]interface{}{
- "id": "proj_1",
- "name": "API Service",
- "status": "active",
- },
- map[string]interface{}{
- "id": "proj_2",
- "name": "Database Optimization",
- "status": "planning",
- },
- },
- },
- map[string]interface{}{
- "lead": "Bob",
- "members": []interface{}{
- map[string]interface{}{
- "id": 3.0,
- "level": "senior",
- "name": "Bob",
- },
- map[string]interface{}{
- "id": 4.0,
- "level": "junior",
- "name": "Carol",
- },
- },
- "name": "Frontend",
- "projects": []interface{}{
- map[string]interface{}{
- "id": "proj_3",
- "name": "Web App",
- "status": "active",
- },
- },
- },
- },
- },
- map[string]interface{}{
- "manager": "Charlie",
- "name": "Sales",
- "teams": []interface{}{
- map[string]interface{}{
- "lead": "Dave",
- "members": []interface{}{
- map[string]interface{}{
- "id": 5.0,
- "level": "senior",
- "name": "Dave",
- },
- map[string]interface{}{
- "id": 6.0,
- "level": "mid",
- "name": "Eve",
- },
- },
- "name": "Enterprise",
- "projects": []interface{}{
- },
- },
- },
- },
- },
- "id": "org_123",
- "metadata": map[string]interface{}{
- "employees": 150.0,
- "founded": "2020",
- "locations": []interface{}{
- "USA",
- "EU",
- "APAC",
- },
- },
- "name": "TechCorp",
- },
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_mixed_types.snap b/__snapshots__/test_snap_j_s_o_n_mixed_types.snap
deleted file mode 100644
index 1ecf623..0000000
--- a/__snapshots__/test_snap_j_s_o_n_mixed_types.snap
+++ /dev/null
@@ -1,42 +0,0 @@
----
-title: SnapJSON Mixed Types
-test_name: TestSnapJSONMixedTypes
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "complex": []interface{}{
- map[string]interface{}{
- "id": 1.0,
- "type": "user",
- },
- map[string]interface{}{
- "id": 100.0,
- "type": "post",
- },
- []interface{}{
- 1.0,
- 2.0,
- 3.0,
- },
- "string",
- nil,
- },
- "mixed_array": []interface{}{
- "string",
- 123.0,
- 45.67,
- true,
- false,
- nil,
- map[string]interface{}{
- "nested": "object",
- },
- []interface{}{
- 1.0,
- 2.0,
- 3.0,
- },
- },
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_real_world_example.snap b/__snapshots__/test_snap_j_s_o_n_real_world_example.snap
deleted file mode 100644
index a981571..0000000
--- a/__snapshots__/test_snap_j_s_o_n_real_world_example.snap
+++ /dev/null
@@ -1,85 +0,0 @@
----
-title: SnapJSON Real World Example
-test_name: TestSnapJSONRealWorldExample
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "data": map[string]interface{}{
- "product": map[string]interface{}{
- "description": "High-quality wireless headphones with noise cancellation",
- "id": "prod_12345",
- "inventory": map[string]interface{}{
- "available": 425.0,
- "damaged": 25.0,
- "reserved": 50.0,
- "total": 500.0,
- },
- "name": "Premium Wireless Headphones",
- "price": map[string]interface{}{
- "amount": 199.99,
- "currency": "USD",
- "discount": 10.0,
- "final_price": 179.99,
- },
- "ratings": map[string]interface{}{
- "average": 4.5,
- "breakdown": map[string]interface{}{
- "1": 20.0,
- "2": 30.0,
- "3": 100.0,
- "4": 350.0,
- "5": 750.0,
- },
- "count": 1250.0,
- },
- "reviews": []interface{}{
- map[string]interface{}{
- "content": "Great sound quality and comfortable to wear.",
- "created_at": "2023-11-15T10:30:00Z",
- "helpful": 25.0,
- "id": "rev_001",
- "rating": 5.0,
- "title": "Excellent product!",
- "user": "john_doe",
- },
- map[string]interface{}{
- "content": "Works well, could be cheaper.",
- "created_at": "2023-11-10T14:20:00Z",
- "helpful": 12.0,
- "id": "rev_002",
- "rating": 4.0,
- "title": "Good but pricey",
- "user": "jane_smith",
- },
- },
- "sku": "PWH-001",
- "specifications": map[string]interface{}{
- "battery_life": "30 hours",
- "colors": []interface{}{
- "black",
- "white",
- "blue",
- },
- "warranty_months": 24.0,
- "weight": "250g",
- },
- },
- "related_products": []interface{}{
- map[string]interface{}{
- "id": "prod_12346",
- "name": "Headphone Case",
- "price": 29.99,
- },
- map[string]interface{}{
- "id": "prod_12347",
- "name": "Audio Cable",
- "price": 14.99,
- },
- },
- },
- "request_id": "req_abc123def456",
- "success": true,
- "timestamp": "2023-11-18T22:00:00Z",
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_simple_array.snap b/__snapshots__/test_snap_j_s_o_n_simple_array.snap
deleted file mode 100644
index 6ba0efa..0000000
--- a/__snapshots__/test_snap_j_s_o_n_simple_array.snap
+++ /dev/null
@@ -1,13 +0,0 @@
----
-title: SnapJSON Simple Array
-test_name: TestSnapJSONSimpleArray
-file_path:
-func_name:
-version: 0.1.0
----
-[]interface{}{
- "apple",
- "banana",
- "orange",
- "grape",
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_with_nested_objects.snap b/__snapshots__/test_snap_j_s_o_n_with_nested_objects.snap
deleted file mode 100644
index 95aae1e..0000000
--- a/__snapshots__/test_snap_j_s_o_n_with_nested_objects.snap
+++ /dev/null
@@ -1,27 +0,0 @@
----
-title: SnapJSON Nested Objects
-test_name: TestSnapJSONWithNestedObjects
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "created_at": "2023-06-15T10:30:00Z",
- "user": map[string]interface{}{
- "id": 42.0,
- "permissions": []interface{}{
- "read",
- "write",
- "admin",
- },
- "profile": map[string]interface{}{
- "avatar": "https://example.com/avatar.jpg",
- "settings": map[string]interface{}{
- "language": "en",
- "notifications": true,
- "theme": "dark",
- },
- "username": "jane_smith",
- },
- },
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_with_nulls.snap b/__snapshots__/test_snap_j_s_o_n_with_nulls.snap
deleted file mode 100644
index c9a0649..0000000
--- a/__snapshots__/test_snap_j_s_o_n_with_nulls.snap
+++ /dev/null
@@ -1,19 +0,0 @@
----
-title: SnapJSON With Nulls
-test_name: TestSnapJSONWithNulls
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "category": nil,
- "description": nil,
- "id": 1.0,
- "metadata": map[string]interface{}{
- "created": "2023-01-01",
- "deleted": nil,
- "updated": nil,
- },
- "name": "Item",
- "tags": nil,
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_with_numbers.snap b/__snapshots__/test_snap_j_s_o_n_with_numbers.snap
deleted file mode 100644
index 6a3e167..0000000
--- a/__snapshots__/test_snap_j_s_o_n_with_numbers.snap
+++ /dev/null
@@ -1,35 +0,0 @@
----
-title: SnapJSON With Numbers
-test_name: TestSnapJSONWithNumbers
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "financial": map[string]interface{}{
- "expenses": 750000.75,
- "profit_margin": 0.2499,
- "revenue": 1.0000005e+06,
- },
- "floats": []interface{}{
- 0.0,
- 3.14,
- -2.5,
- 0.001,
- 0.000123,
- 5.67e+10.0,
- },
- "integers": []interface{}{
- 0.0,
- 1.0,
- -1.0,
- 42.0,
- -100.0,
- 9.999999e+06.0,
- },
- "measurements": map[string]interface{}{
- "distance": 1000.25,
- "temperature": -40.5,
- "weight": 0.5,
- },
-}
diff --git a/__snapshots__/test_snap_j_s_o_n_with_special_characters.snap b/__snapshots__/test_snap_j_s_o_n_with_special_characters.snap
deleted file mode 100644
index 689cceb..0000000
--- a/__snapshots__/test_snap_j_s_o_n_with_special_characters.snap
+++ /dev/null
@@ -1,16 +0,0 @@
----
-title: SnapJSON With Special Characters
-test_name: TestSnapJSONWithSpecialCharacters
-file_path:
-func_name:
-version: 0.1.0
----
-map[string]interface{}{
- "escaped": "line1\nline2\ttab\rcarriage",
- "html": "
Content
",
- "paths": "C:\\Users\\name\\Documents\\file.txt",
- "quotes": "He said \"hello\" and she said 'goodbye'",
- "regex": "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$",
- "special": "!@#$%^&*()_+-=[]{}|;:',.<>?/",
- "unicode": "Hello ไธ็ ๐ ู
ุฑุญุจุง ะัะธะฒะตั",
-}
diff --git a/__snapshots__/test_snap_json_array_of_objects.snap b/__snapshots__/test_snap_json_array_of_objects.snap
new file mode 100644
index 0000000..3a1e222
--- /dev/null
+++ b/__snapshots__/test_snap_json_array_of_objects.snap
@@ -0,0 +1,30 @@
+---
+title: SnapJSON Array of Objects
+test_name: TestSnapJsonArrayOfObjects
+file_path:
+func_name:
+version: 0.1.0
+---
+[
+ {
+ "id": 1,
+ "likes": 42,
+ "title": "First Post",
+ "type": "post",
+ "views": 150
+ },
+ {
+ "id": 2,
+ "likes": 75,
+ "title": "Second Post",
+ "type": "post",
+ "views": 280
+ },
+ {
+ "id": 3,
+ "likes": 120,
+ "title": "Third Post",
+ "type": "post",
+ "views": 450
+ }
+]
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_basic.snap b/__snapshots__/test_snap_json_basic.snap
new file mode 100644
index 0000000..b0f6fa2
--- /dev/null
+++ b/__snapshots__/test_snap_json_basic.snap
@@ -0,0 +1,13 @@
+---
+title: SnapJSON Basic Object
+test_name: TestSnapJsonBasic
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "age": 30,
+ "email": "john@example.com",
+ "name": "John Doe",
+ "verified": true
+}
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_compact_format.snap b/__snapshots__/test_snap_json_compact_format.snap
new file mode 100644
index 0000000..29a6109
--- /dev/null
+++ b/__snapshots__/test_snap_json_compact_format.snap
@@ -0,0 +1,17 @@
+---
+title: SnapJSON Compact Format
+test_name: TestSnapJsonCompactFormat
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "id": 1,
+ "in_stock": true,
+ "name": "Product",
+ "price": 99.99,
+ "tags": [
+ "electronics",
+ "gadgets"
+ ]
+}
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_complex_a_p_i.snap b/__snapshots__/test_snap_json_complex_a_p_i.snap
new file mode 100644
index 0000000..bbe116c
--- /dev/null
+++ b/__snapshots__/test_snap_json_complex_a_p_i.snap
@@ -0,0 +1,43 @@
+---
+title: SnapJSON Complex API Response
+test_name: TestSnapJsonComplexAPI
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "code": 200,
+ "data": {
+ "pagination": {
+ "page": 1,
+ "per_page": 10,
+ "total": 3,
+ "total_pages": 1
+ },
+ "users": [
+ {
+ "active": true,
+ "department": "Engineering",
+ "id": 1,
+ "name": "Alice",
+ "role": "admin"
+ },
+ {
+ "active": true,
+ "department": "Sales",
+ "id": 2,
+ "name": "Bob",
+ "role": "user"
+ },
+ {
+ "active": false,
+ "department": "Marketing",
+ "id": 3,
+ "name": "Charlie",
+ "role": "user"
+ }
+ ]
+ },
+ "status": "success",
+ "timestamp": "2023-11-18T21:45:30Z"
+}
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_empty_structures.snap b/__snapshots__/test_snap_json_empty_structures.snap
new file mode 100644
index 0000000..157592e
--- /dev/null
+++ b/__snapshots__/test_snap_json_empty_structures.snap
@@ -0,0 +1,19 @@
+---
+title: SnapJSON Empty Structures
+test_name: TestSnapJsonEmptyStructures
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "empty_array": [],
+ "empty_object": {},
+ "empty_string": "",
+ "false_value": false,
+ "nested": {
+ "also_empty": {},
+ "empty": []
+ },
+ "null_value": null,
+ "zero": 0
+}
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_large_nested_structure.snap b/__snapshots__/test_snap_json_large_nested_structure.snap
new file mode 100644
index 0000000..ced476a
--- /dev/null
+++ b/__snapshots__/test_snap_json_large_nested_structure.snap
@@ -0,0 +1,104 @@
+---
+title: SnapJSON Large Nested Structure
+test_name: TestSnapJsonLargeNestedStructure
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "organization": {
+ "departments": [
+ {
+ "manager": "Alice",
+ "name": "Engineering",
+ "teams": [
+ {
+ "lead": "John",
+ "members": [
+ {
+ "id": 1,
+ "level": "senior",
+ "name": "John"
+ },
+ {
+ "id": 2,
+ "level": "mid",
+ "name": "Jane"
+ }
+ ],
+ "name": "Backend",
+ "projects": [
+ {
+ "id": "proj_1",
+ "name": "API Service",
+ "status": "active"
+ },
+ {
+ "id": "proj_2",
+ "name": "Database Optimization",
+ "status": "planning"
+ }
+ ]
+ },
+ {
+ "lead": "Bob",
+ "members": [
+ {
+ "id": 3,
+ "level": "senior",
+ "name": "Bob"
+ },
+ {
+ "id": 4,
+ "level": "junior",
+ "name": "Carol"
+ }
+ ],
+ "name": "Frontend",
+ "projects": [
+ {
+ "id": "proj_3",
+ "name": "Web App",
+ "status": "active"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "manager": "Charlie",
+ "name": "Sales",
+ "teams": [
+ {
+ "lead": "Dave",
+ "members": [
+ {
+ "id": 5,
+ "level": "senior",
+ "name": "Dave"
+ },
+ {
+ "id": 6,
+ "level": "mid",
+ "name": "Eve"
+ }
+ ],
+ "name": "Enterprise",
+ "projects": []
+ }
+ ]
+ }
+ ],
+ "id": "org_123",
+ "metadata": {
+ "employees": 150,
+ "founded": "2020",
+ "locations": [
+ "USA",
+ "EU",
+ "APAC"
+ ]
+ },
+ "name": "TechCorp"
+ }
+}
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_mixed_types.snap b/__snapshots__/test_snap_json_mixed_types.snap
new file mode 100644
index 0000000..204cca3
--- /dev/null
+++ b/__snapshots__/test_snap_json_mixed_types.snap
@@ -0,0 +1,42 @@
+---
+title: SnapJSON Mixed Types
+test_name: TestSnapJsonMixedTypes
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "complex": [
+ {
+ "id": 1,
+ "type": "user"
+ },
+ {
+ "id": 100,
+ "type": "post"
+ },
+ [
+ 1,
+ 2,
+ 3
+ ],
+ "string",
+ null
+ ],
+ "mixed_array": [
+ "string",
+ 123,
+ 45.67,
+ true,
+ false,
+ null,
+ {
+ "nested": "object"
+ },
+ [
+ 1,
+ 2,
+ 3
+ ]
+ ]
+}
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_real_world_example.snap b/__snapshots__/test_snap_json_real_world_example.snap
new file mode 100644
index 0000000..1d83abf
--- /dev/null
+++ b/__snapshots__/test_snap_json_real_world_example.snap
@@ -0,0 +1,85 @@
+---
+title: SnapJSON Real World Example
+test_name: TestSnapJsonRealWorldExample
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "data": {
+ "product": {
+ "description": "High-quality wireless headphones with noise cancellation",
+ "id": "prod_12345",
+ "inventory": {
+ "available": 425,
+ "damaged": 25,
+ "reserved": 50,
+ "total": 500
+ },
+ "name": "Premium Wireless Headphones",
+ "price": {
+ "amount": 199.99,
+ "currency": "USD",
+ "discount": 10,
+ "final_price": 179.99
+ },
+ "ratings": {
+ "average": 4.5,
+ "breakdown": {
+ "1": 20,
+ "2": 30,
+ "3": 100,
+ "4": 350,
+ "5": 750
+ },
+ "count": 1250
+ },
+ "reviews": [
+ {
+ "content": "Great sound quality and comfortable to wear.",
+ "created_at": "2023-11-15T10:30:00Z",
+ "helpful": 25,
+ "id": "rev_001",
+ "rating": 5,
+ "title": "Excellent product!",
+ "user": "john_doe"
+ },
+ {
+ "content": "Works well, could be cheaper.",
+ "created_at": "2023-11-10T14:20:00Z",
+ "helpful": 12,
+ "id": "rev_002",
+ "rating": 4,
+ "title": "Good but pricey",
+ "user": "jane_smith"
+ }
+ ],
+ "sku": "PWH-001",
+ "specifications": {
+ "battery_life": "30 hours",
+ "colors": [
+ "black",
+ "white",
+ "blue"
+ ],
+ "warranty_months": 24,
+ "weight": "250g"
+ }
+ },
+ "related_products": [
+ {
+ "id": "prod_12346",
+ "name": "Headphone Case",
+ "price": 29.99
+ },
+ {
+ "id": "prod_12347",
+ "name": "Audio Cable",
+ "price": 14.99
+ }
+ ]
+ },
+ "request_id": "req_abc123def456",
+ "success": true,
+ "timestamp": "2023-11-18T22:00:00Z"
+}
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_simple_array.snap b/__snapshots__/test_snap_json_simple_array.snap
new file mode 100644
index 0000000..46af977
--- /dev/null
+++ b/__snapshots__/test_snap_json_simple_array.snap
@@ -0,0 +1,13 @@
+---
+title: SnapJSON Simple Array
+test_name: TestSnapJsonSimpleArray
+file_path:
+func_name:
+version: 0.1.0
+---
+[
+ "apple",
+ "banana",
+ "orange",
+ "grape"
+]
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_with_nested_objects.snap b/__snapshots__/test_snap_json_with_nested_objects.snap
new file mode 100644
index 0000000..0ab8df0
--- /dev/null
+++ b/__snapshots__/test_snap_json_with_nested_objects.snap
@@ -0,0 +1,27 @@
+---
+title: SnapJSON Nested Objects
+test_name: TestSnapJsonWithNestedObjects
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "created_at": "2023-06-15T10:30:00Z",
+ "user": {
+ "id": 42,
+ "permissions": [
+ "read",
+ "write",
+ "admin"
+ ],
+ "profile": {
+ "avatar": "https://example.com/avatar.jpg",
+ "settings": {
+ "language": "en",
+ "notifications": true,
+ "theme": "dark"
+ },
+ "username": "jane_smith"
+ }
+ }
+}
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_with_nulls.snap b/__snapshots__/test_snap_json_with_nulls.snap
new file mode 100644
index 0000000..f8e7fe0
--- /dev/null
+++ b/__snapshots__/test_snap_json_with_nulls.snap
@@ -0,0 +1,19 @@
+---
+title: SnapJSON With Nulls
+test_name: TestSnapJsonWithNulls
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "category": null,
+ "description": null,
+ "id": 1,
+ "metadata": {
+ "created": "2023-01-01",
+ "deleted": null,
+ "updated": null
+ },
+ "name": "Item",
+ "tags": null
+}
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_with_numbers.snap b/__snapshots__/test_snap_json_with_numbers.snap
new file mode 100644
index 0000000..ea1fe12
--- /dev/null
+++ b/__snapshots__/test_snap_json_with_numbers.snap
@@ -0,0 +1,35 @@
+---
+title: SnapJSON With Numbers
+test_name: TestSnapJsonWithNumbers
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "financial": {
+ "expenses": 750000.75,
+ "profit_margin": 0.2499,
+ "revenue": 1000000.5
+ },
+ "floats": [
+ 0,
+ 3.14,
+ -2.5,
+ 0.001,
+ 0.000123,
+ 56700000000
+ ],
+ "integers": [
+ 0,
+ 1,
+ -1,
+ 42,
+ -100,
+ 9999999
+ ],
+ "measurements": {
+ "distance": 1000.25,
+ "temperature": -40.5,
+ "weight": 0.5
+ }
+}
\ No newline at end of file
diff --git a/__snapshots__/test_snap_json_with_special_characters.snap b/__snapshots__/test_snap_json_with_special_characters.snap
new file mode 100644
index 0000000..8cad1cd
--- /dev/null
+++ b/__snapshots__/test_snap_json_with_special_characters.snap
@@ -0,0 +1,16 @@
+---
+title: SnapJSON With Special Characters
+test_name: TestSnapJsonWithSpecialCharacters
+file_path:
+func_name:
+version: 0.1.0
+---
+{
+ "escaped": "line1\nline2\ttab\rcarriage",
+ "html": "\u003cdiv class=\"container\"\u003eContent\u003c/div\u003e",
+ "paths": "C:\\Users\\name\\Documents\\file.txt",
+ "quotes": "He said \"hello\" and she said 'goodbye'",
+ "regex": "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$",
+ "special": "!@#$%^\u0026*()_+-=[]{}|;:',.\u003c\u003e?/",
+ "unicode": "Hello ไธ็ ๐ ู
ุฑุญุจุง ะัะธะฒะตั"
+}
\ No newline at end of file
diff --git a/api.go b/api.go
index ad58b13..33b0076 100644
--- a/api.go
+++ b/api.go
@@ -1,47 +1,46 @@
package freeze
import (
- "github.com/ptdewey/freeze/internal/api"
+ "github.com/ptdewey/freeze/internal/diff"
+ "github.com/ptdewey/freeze/internal/files"
+ "github.com/ptdewey/freeze/internal/pretty"
)
-type Snapshot = api.Snapshot
+type Snapshot = files.Snapshot
-type DiffLine = api.DiffLine
+type DiffLine = diff.DiffLine
const (
- DiffShared = api.DiffShared
- DiffOld = api.DiffOld
- DiffNew = api.DiffNew
+ DiffShared = diff.DiffShared
+ DiffOld = diff.DiffOld
+ DiffNew = diff.DiffNew
)
func Deserialize(raw string) (*Snapshot, error) {
- return api.Deserialize(raw)
+ return files.Deserialize(raw)
}
func SaveSnapshot(snap *Snapshot, state string) error {
- return api.SaveSnapshot(snap, state)
+ return files.SaveSnapshot(snap, state)
}
func ReadSnapshot(testName string, state string) (*Snapshot, error) {
- return api.ReadSnapshot(testName, state)
+ return files.ReadSnapshot(testName, state)
}
func SnapshotFileName(testName string) string {
- return api.SnapshotFileName(testName)
+ return files.SnapshotFileName(testName)
}
func Histogram(old, new string) []DiffLine {
- return api.Histogram(old, new)
+ return diff.Histogram(old, new)
}
func NewSnapshotBox(snap *Snapshot) string {
- return api.NewSnapshotBox(snap)
+ return pretty.NewSnapshotBox(snap)
}
-func NewSnapshotBoxFunc(snap *Snapshot) string {
- return api.NewSnapshotBoxFunc(snap)
-}
-
-func DiffSnapshotBox(old, new *Snapshot) string {
- return api.DiffSnapshotBox(old, new)
+func DiffSnapshotBox(oldSnap, newSnap *Snapshot) string {
+ diffLines := convertDiffLines(diff.Histogram(oldSnap.Content, newSnap.Content))
+ return pretty.DiffSnapshotBox(oldSnap, newSnap, diffLines)
}
diff --git a/cmd/tui/main.go b/cmd/tui/main.go
index 2b7492a..974b2d7 100644
--- a/cmd/tui/main.go
+++ b/cmd/tui/main.go
@@ -271,11 +271,7 @@ func (m *model) updateViewportContent() {
b.WriteString(pretty.DiffSnapshotBox(m.accepted, m.newSnap, m.diffLines))
} else {
if m.newSnap != nil {
- if m.newSnap.FuncName != "" {
- b.WriteString(pretty.NewSnapshotBoxFunc(m.newSnap))
- } else {
- b.WriteString(pretty.NewSnapshotBox(m.newSnap))
- }
+ b.WriteString(pretty.NewSnapshotBox(m.newSnap))
}
}
diff --git a/freeze.go b/freeze.go
index fe6f1b1..24d45aa 100644
--- a/freeze.go
+++ b/freeze.go
@@ -24,9 +24,9 @@ func SnapString(t testingT, title string, content string) {
snap(t, title, content)
}
-// SnapJSON takes a JSON string, unmarshals it, and then marshals it back with
-// pretty-printing before snapshotting. This ensures consistent formatting and
-// validates the JSON structure.
+// SnapJSON takes a JSON string, validates it, and pretty-prints it with
+// consistent formatting before snapshotting. This preserves the raw JSON
+// format while ensuring valid JSON structure.
func SnapJSON(t testingT, title string, jsonStr string) {
t.Helper()
@@ -36,9 +36,14 @@ func SnapJSON(t testingT, title string, jsonStr string) {
return
}
- // Format the JSON data using the same mechanism as Snap
- content := formatValue(data)
- snap(t, title, content)
+ // Pretty-print the JSON with consistent indentation
+ prettyJSON, err := json.MarshalIndent(data, "", " ")
+ if err != nil {
+ t.Error("failed to marshal JSON:", err)
+ return
+ }
+
+ snap(t, title, string(prettyJSON))
}
func Snap(t testingT, title string, values ...any) {
diff --git a/freeze_test.go b/freeze_test.go
index 1fbe932..0d4a080 100644
--- a/freeze_test.go
+++ b/freeze_test.go
@@ -9,7 +9,7 @@ import (
"time"
"github.com/ptdewey/freeze"
- "github.com/ptdewey/freeze/internal/api"
+ "github.com/ptdewey/freeze/internal/files"
)
func TestSnapString(t *testing.T) {
@@ -80,7 +80,7 @@ func TestFileOperations(t *testing.T) {
Content: "file test content",
}
- if err := api.SaveSnapshot(snap, "test"); err != nil {
+ if err := files.SaveSnapshot(snap, "test"); err != nil {
t.Fatalf("failed to save snapshot: %v", err)
}
@@ -534,7 +534,7 @@ func TestStructureWithEmptyValues(t *testing.T) {
// ============================================================================
// TestJSONObject tests snapshot with JSON objects
-func TestJSONObject(t *testing.T) {
+func TestJsonObject(t *testing.T) {
jsonStr := `{
"user": {
"id": 1,
@@ -562,7 +562,7 @@ func TestJSONObject(t *testing.T) {
}
// TestComplexJSONStructure tests complex nested JSON structures
-func TestComplexJSONStructure(t *testing.T) {
+func TestComplexJsonStructure(t *testing.T) {
jsonStr := `{
"api": {
"version": "2.0",
@@ -631,7 +631,7 @@ func TestComplexJSONStructure(t *testing.T) {
}
// TestJSONArrayOfObjects tests JSON arrays with multiple object types
-func TestJSONArrayOfObjects(t *testing.T) {
+func TestJsonArrayOfObjects(t *testing.T) {
jsonStr := `[
{
"type": "user",
@@ -670,7 +670,7 @@ func TestJSONArrayOfObjects(t *testing.T) {
}
// TestJSONWithVariousTypes tests JSON with various data types
-func TestJSONWithVariousTypes(t *testing.T) {
+func TestJsonWithVariousTypes(t *testing.T) {
jsonStr := `{
"string": "hello world",
"integer": 42,
@@ -697,7 +697,7 @@ func TestJSONWithVariousTypes(t *testing.T) {
}
// TestJSONNumbers tests JSON with various number formats
-func TestJSONNumbers(t *testing.T) {
+func TestJsonNumbers(t *testing.T) {
jsonStr := `{
"integers": {
"zero": 0,
@@ -726,7 +726,7 @@ func TestJSONNumbers(t *testing.T) {
}
// TestJSONWithSpecialCharacters tests JSON with special characters and unicode
-func TestJSONWithSpecialCharacters(t *testing.T) {
+func TestJsonWithSpecialCharacters(t *testing.T) {
jsonStr := `{
"english": "Hello, World!",
"unicode": "ใใใซใกใฏ ไธ็ ๐",
@@ -747,7 +747,7 @@ func TestJSONWithSpecialCharacters(t *testing.T) {
}
// TestGoStructMarshalledToJSON tests Go struct marshalled to JSON
-func TestGoStructMarshalledToJSON(t *testing.T) {
+func TestGoStructMarshalledToJson(t *testing.T) {
type Address struct {
Street string `json:"street"`
City string `json:"city"`
@@ -792,7 +792,7 @@ func TestGoStructMarshalledToJSON(t *testing.T) {
}
// TestDeeplyNestedJSON tests deeply nested JSON structure
-func TestDeeplyNestedJSON(t *testing.T) {
+func TestDeeplyNestedJson(t *testing.T) {
type Level4 struct {
Value string
}
@@ -833,7 +833,7 @@ func TestDeeplyNestedJSON(t *testing.T) {
}
// TestLargeJSON tests larger JSON structure with many fields
-func TestLargeJSON(t *testing.T) {
+func TestLargeJson(t *testing.T) {
type Product struct {
ID int `json:"id"`
Name string `json:"name"`
@@ -910,7 +910,7 @@ func TestLargeJSON(t *testing.T) {
}
// TestJSONWithMixedArrays tests JSON with arrays containing different types
-func TestJSONWithMixedArrays(t *testing.T) {
+func TestJsonWithMixedArrays(t *testing.T) {
jsonStr := `{
"heterogeneous_array": [
"string",
@@ -946,7 +946,7 @@ func TestJSONWithMixedArrays(t *testing.T) {
// ============================================================================
// TestSnapJSONBasic tests the SnapJSON function with basic JSON
-func TestSnapJSONBasic(t *testing.T) {
+func TestSnapJsonBasic(t *testing.T) {
jsonStr := `{
"name": "John Doe",
"email": "john@example.com",
@@ -958,7 +958,7 @@ func TestSnapJSONBasic(t *testing.T) {
}
// TestSnapJSONSimpleArray tests SnapJSON with simple arrays
-func TestSnapJSONSimpleArray(t *testing.T) {
+func TestSnapJsonSimpleArray(t *testing.T) {
jsonStr := `[
"apple",
"banana",
@@ -970,14 +970,14 @@ func TestSnapJSONSimpleArray(t *testing.T) {
}
// TestSnapJSONCompactFormat tests SnapJSON with compact (minified) JSON
-func TestSnapJSONCompactFormat(t *testing.T) {
+func TestSnapJsonCompactFormat(t *testing.T) {
jsonStr := `{"id":1,"name":"Product","price":99.99,"in_stock":true,"tags":["electronics","gadgets"]}`
freeze.SnapJSON(t, "SnapJSON Compact Format", jsonStr)
}
// TestSnapJSONWithNestedObjects tests SnapJSON with nested JSON structures
-func TestSnapJSONWithNestedObjects(t *testing.T) {
+func TestSnapJsonWithNestedObjects(t *testing.T) {
jsonStr := `{
"user": {
"id": 42,
@@ -999,7 +999,7 @@ func TestSnapJSONWithNestedObjects(t *testing.T) {
}
// TestSnapJSONComplexAPI tests SnapJSON with complex API response
-func TestSnapJSONComplexAPI(t *testing.T) {
+func TestSnapJsonComplexAPI(t *testing.T) {
jsonStr := `{
"status": "success",
"code": 200,
@@ -1041,7 +1041,7 @@ func TestSnapJSONComplexAPI(t *testing.T) {
}
// TestSnapJSONWithNulls tests SnapJSON handling of null values
-func TestSnapJSONWithNulls(t *testing.T) {
+func TestSnapJsonWithNulls(t *testing.T) {
jsonStr := `{
"id": 1,
"name": "Item",
@@ -1059,7 +1059,7 @@ func TestSnapJSONWithNulls(t *testing.T) {
}
// TestSnapJSONArrayOfObjects tests SnapJSON with arrays of objects
-func TestSnapJSONArrayOfObjects(t *testing.T) {
+func TestSnapJsonArrayOfObjects(t *testing.T) {
jsonStr := `[
{
"id": 1,
@@ -1088,7 +1088,7 @@ func TestSnapJSONArrayOfObjects(t *testing.T) {
}
// TestSnapJSONLargeNestedStructure tests SnapJSON with deeply nested JSON
-func TestSnapJSONLargeNestedStructure(t *testing.T) {
+func TestSnapJsonLargeNestedStructure(t *testing.T) {
jsonStr := `{
"organization": {
"name": "TechCorp",
@@ -1151,7 +1151,7 @@ func TestSnapJSONLargeNestedStructure(t *testing.T) {
}
// TestSnapJSONWithNumbers tests SnapJSON with various number formats
-func TestSnapJSONWithNumbers(t *testing.T) {
+func TestSnapJsonWithNumbers(t *testing.T) {
jsonStr := `{
"integers": [0, 1, -1, 42, -100, 9999999],
"floats": [0.0, 3.14, -2.5, 0.001, 1.23e-4, 5.67e10],
@@ -1171,7 +1171,7 @@ func TestSnapJSONWithNumbers(t *testing.T) {
}
// TestSnapJSONWithSpecialCharacters tests SnapJSON with special chars
-func TestSnapJSONWithSpecialCharacters(t *testing.T) {
+func TestSnapJsonWithSpecialCharacters(t *testing.T) {
jsonStr := `{
"special": "!@#$%^&*()_+-=[]{}|;:',.<>?/",
"escaped": "line1\nline2\ttab\rcarriage",
@@ -1186,7 +1186,7 @@ func TestSnapJSONWithSpecialCharacters(t *testing.T) {
}
// TestSnapJSONEmptyStructures tests SnapJSON with empty collections
-func TestSnapJSONEmptyStructures(t *testing.T) {
+func TestSnapJsonEmptyStructures(t *testing.T) {
jsonStr := `{
"empty_array": [],
"empty_object": {},
@@ -1204,7 +1204,7 @@ func TestSnapJSONEmptyStructures(t *testing.T) {
}
// TestSnapJSONMixedTypes tests SnapJSON with mixed array types
-func TestSnapJSONMixedTypes(t *testing.T) {
+func TestSnapJsonMixedTypes(t *testing.T) {
jsonStr := `{
"mixed_array": [
"string",
@@ -1229,7 +1229,7 @@ func TestSnapJSONMixedTypes(t *testing.T) {
}
// TestSnapJSONRealWorldExample tests SnapJSON with real-world API data
-func TestSnapJSONRealWorldExample(t *testing.T) {
+func TestSnapJsonRealWorldExample(t *testing.T) {
jsonStr := `{
"success": true,
"data": {
diff --git a/internal/api/api.go b/internal/api/api.go
deleted file mode 100644
index 6937f57..0000000
--- a/internal/api/api.go
+++ /dev/null
@@ -1,99 +0,0 @@
-package api
-
-import (
- "github.com/ptdewey/freeze/internal/diff"
- "github.com/ptdewey/freeze/internal/files"
- "github.com/ptdewey/freeze/internal/pretty"
-)
-
-type Snapshot = files.Snapshot
-
-type DiffLine = diff.DiffLine
-
-const (
- DiffShared = diff.DiffShared
- DiffOld = diff.DiffOld
- DiffNew = diff.DiffNew
-)
-
-func Deserialize(raw string) (*Snapshot, error) {
- return files.Deserialize(raw)
-}
-
-func SaveSnapshot(snap *Snapshot, state string) error {
- return files.SaveSnapshot(snap, state)
-}
-
-func ReadSnapshot(testName string, state string) (*Snapshot, error) {
- return files.ReadSnapshot(testName, state)
-}
-
-func SnapshotFileName(testName string) string {
- return files.SnapshotFileName(testName)
-}
-
-func Histogram(old, new string) []DiffLine {
- return diff.Histogram(old, new)
-}
-
-func NewSnapshotBox(snap *Snapshot) string {
- return pretty.NewSnapshotBox(snap)
-}
-
-func NewSnapshotBoxFunc(snap *Snapshot) string {
- return pretty.NewSnapshotBoxFunc(snap)
-}
-
-func DiffSnapshotBox(old, new *Snapshot) string {
- diffLines := convertDiffLines(diff.Histogram(old.Content, new.Content))
- return pretty.DiffSnapshotBox(old, new, diffLines)
-}
-
-func convertDiffLines(diffLines []diff.DiffLine) []pretty.DiffLine {
- result := make([]pretty.DiffLine, len(diffLines))
- for i, dl := range diffLines {
- result[i] = pretty.DiffLine{
- OldNumber: dl.OldNumber,
- NewNumber: dl.NewNumber,
- Line: dl.Line,
- Kind: pretty.DiffKind(dl.Kind),
- }
- }
- return result
-}
-
-func Red(s string) string {
- return pretty.Red(s)
-}
-
-func Green(s string) string {
- return pretty.Green(s)
-}
-
-func Yellow(s string) string {
- return pretty.Yellow(s)
-}
-
-func Blue(s string) string {
- return pretty.Blue(s)
-}
-
-func Gray(s string) string {
- return pretty.Gray(s)
-}
-
-func Bold(s string) string {
- return pretty.Bold(s)
-}
-
-func TerminalWidth() int {
- return pretty.TerminalWidth()
-}
-
-func ClearScreen() {
- pretty.ClearScreen()
-}
-
-func ClearLine() {
- pretty.ClearLine()
-}
diff --git a/__snapshots__/test_accept.snap b/internal/files/__snapshots__/test_accept.snap
similarity index 100%
rename from __snapshots__/test_accept.snap
rename to internal/files/__snapshots__/test_accept.snap
diff --git a/internal/files/files.go b/internal/files/files.go
index d2355dd..e454819 100644
--- a/internal/files/files.go
+++ b/internal/files/files.go
@@ -18,7 +18,10 @@ type Snapshot struct {
}
func (s *Snapshot) Serialize() string {
- header := fmt.Sprintf("---\ntitle: %s\ntest_name: %s\nfile_path: %s\nfunc_name: %s\nversion: %s\n---\n", s.Title, s.Name, s.FilePath, s.FuncName, s.Version)
+ header := fmt.Sprintf(
+ "---\ntitle: %s\ntest_name: %s\nfile_path: %s\nfunc_name: %s\nversion: %s\n---\n",
+ s.Title, s.Name, s.FilePath, s.FuncName, s.Version,
+ )
return header + s.Content
}
@@ -64,6 +67,7 @@ func Deserialize(raw string) (*Snapshot, error) {
return snap, nil
}
+// TODO: make snapshots in root vs package dirs a configurable option?
func findProjectRoot() (string, error) {
cwd, err := os.Getwd()
if err != nil {
@@ -85,12 +89,14 @@ func findProjectRoot() (string, error) {
}
func getSnapshotDir() (string, error) {
- root, err := findProjectRoot()
- if err != nil {
- return "", err
- }
-
- snapshotDir := filepath.Join(root, "__snapshots__")
+ // NOTE: maybe this could be configurable?
+ // Storing snapshots in root may be desirable in some cases
+ // root, err := findProjectRoot()
+ // if err != nil {
+ // return "", err
+ // }
+ // snapshotDir := filepath.Join(root, "__snapshots__")
+ snapshotDir := "__snapshots__"
if err := os.MkdirAll(snapshotDir, 0755); err != nil {
return "", err
}
diff --git a/internal/pretty/boxes.go b/internal/pretty/boxes.go
index 5050f1c..9347828 100644
--- a/internal/pretty/boxes.go
+++ b/internal/pretty/boxes.go
@@ -23,7 +23,7 @@ const (
DiffNew
)
-func newSnapshotBoxInternal(snap *files.Snapshot, isFuncSnapshot bool) string {
+func newSnapshotBoxInternal(snap *files.Snapshot) string {
width := TerminalWidth()
snapshotFileName := files.SnapshotFileName(snap.Name) + ".snap.new"
@@ -36,6 +36,7 @@ func newSnapshotBoxInternal(snap *files.Snapshot, isFuncSnapshot bool) string {
if snap.Name != "" {
sb.WriteString(fmt.Sprintf(" test: %s\n", Blue(snap.Name)))
}
+ // TODO: maybe put this on the "new snapshot row"? (or only show on the diff view)
if snapshotFileName != "" {
sb.WriteString(fmt.Sprintf(" file: %s\n", Gray(snapshotFileName)))
}
@@ -45,7 +46,8 @@ func newSnapshotBoxInternal(snap *files.Snapshot, isFuncSnapshot bool) string {
numLines := len(lines)
lineNumWidth := len(strconv.Itoa(numLines))
- topBar := strings.Repeat("โ", lineNumWidth+3) + "โฌ" + strings.Repeat("โ", width-lineNumWidth-2) + "\n"
+ topBar := strings.Repeat("โ", lineNumWidth+3) + "โฌ" +
+ strings.Repeat("โ", width-lineNumWidth-2) + "\n"
sb.WriteString(topBar)
for i, line := range lines {
@@ -60,18 +62,15 @@ func newSnapshotBoxInternal(snap *files.Snapshot, isFuncSnapshot bool) string {
sb.WriteString(fmt.Sprintf(" %s\n", display))
}
- bottomBar := strings.Repeat("โ", lineNumWidth+3) + "โด" + strings.Repeat("โ", width-lineNumWidth-2) + "\n"
+ bottomBar := strings.Repeat("โ", lineNumWidth+3) + "โด" +
+ strings.Repeat("โ", width-lineNumWidth-2) + "\n"
sb.WriteString(bottomBar)
return sb.String()
}
func NewSnapshotBox(snap *files.Snapshot) string {
- return newSnapshotBoxInternal(snap, false)
-}
-
-func NewSnapshotBoxFunc(snap *files.Snapshot) string {
- return newSnapshotBoxInternal(snap, true)
+ return newSnapshotBoxInternal(snap)
}
func DiffSnapshotBox(old, new *files.Snapshot, diffLines []DiffLine) string {