Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

tests update

  • Loading branch information...
commit b7db41a13b8cddf5f80bb98cb05d847565e48f28 1 parent 934da00
Kuleshov Alexander authored

Showing 1 changed file with 48 additions and 20 deletions. Show diff stats Hide diff stats

  1. 68  src/mochijson3_helper.erl
68  src/mochijson3_helper.erl
@@ -18,10 +18,9 @@ get_path_value([], Data) ->
18 18
     Data;
19 19
 
20 20
 %% @doc Find value from mochijson3 output
21  
-%% @end       
  21
+%% @end         
22 22
 get_path_value(Path, RD) when is_list(RD) ->
23 23
     % Check request data length
24  
-    % [{Num, RequestBody}, ...]
25 24
     case length(Path) of
26 25
         1 ->
27 26
             % Get current request body
@@ -29,23 +28,28 @@ get_path_value(Path, RD) when is_list(RD) ->
29 28
             % Find in the data structure
30 29
             FindedData = lists:nth(Num, RD),
31 30
             % Get finded data
32  
-            {struct, NeedToFindValue} = FindedData,    
33  
-            % Get value
34  
-            TryGetValue = lists:keyfind(NeedToFind, 1, NeedToFindValue),
35  
-            case TryGetValue of
36  
-                false ->
37  
-                   error;
38  
-                _ ->
39  
-                  {_, Value} = TryGetValue,
40  
-                  Value
41  
-            end;
  31
+            {MaybeStruct, NeedToFindValue} = FindedData,
  32
+            case MaybeStruct of
  33
+                struct ->
  34
+                    % Get value
  35
+                    TryGetValue = lists:keyfind(NeedToFind, 1, NeedToFindValue),
  36
+                    case TryGetValue of
  37
+                        false ->
  38
+                            error;
  39
+                        _ ->
  40
+                            {_, Value} = TryGetValue,
  41
+                            Value
  42
+                    end;
  43
+                    _ ->
  44
+                        MaybeStruct
  45
+           end;
42 46
         _ ->
43 47
            case RD of
44 48
                [] ->
45 49
                    error;
46 50
                _ ->
47 51
                    % Find further
48  
-                   get_path_value(Path, lists:nth(1, RD))
  52
+                   get_path_value(Path, {struct, RD})
49 53
            end
50 54
     end;
51 55
 
@@ -57,26 +61,50 @@ get_path_value(Path, RD) when is_tuple(RD) ->
57 61
    % Get first request body
58 62
    [H | T] = Path,
59 63
    % Find value
60  
-   {Num, NeedFindValue} = H,   
  64
+   {Num, NeedFindValue} = H, 
  65
+     
61 66
    List = lists:filter(fun(X) -> 
62  
-              {Value, _} = X,
63  
-              Value == NeedFindValue
  67
+              {Value, JSonValue} = X,
  68
+              if
  69
+                  Value == struct ->
  70
+                     TryToFindNext = lists:keyfind(NeedFindValue, 1, JSonValue),
  71
+                     case TryToFindNext of
  72
+                        false ->
  73
+                            false;
  74
+                        _ ->
  75
+                            true  
  76
+                     end;   
  77
+                  true ->
  78
+                     Value == NeedFindValue
  79
+              end
64 80
           end,
65 81
           DataList),
66  
-   % Check list what we find (if we not find sequnces we return error)
  82
+      
67 83
    case List of
68 84
       [] ->
69 85
          error;
70 86
       _ ->
71  
-          % Check 
72 87
           if
73 88
               Num > length(List) ->
74 89
                   error;
75 90
               true ->
76 91
                   % Return value
77 92
                   FindedValue = lists:nth(Num, List),
78  
-                  {NeedFindValue, OtherValue} = FindedValue,
79  
-                  get_path_value(T, OtherValue)
  93
+                  {IsStruct, OtherValue} = FindedValue,
  94
+                  case IsStruct of
  95
+                      struct ->
  96
+                          {struct, FindNextValue} = FindedValue,
  97
+                          TryToFindNextValue = lists:keyfind(NeedFindValue, 1, FindNextValue),
  98
+                          case TryToFindNextValue of
  99
+                              false ->
  100
+                                  error;
  101
+                              _ ->
  102
+                                  {_, Value} = TryToFindNextValue,
  103
+                                  get_path_value(T, Value)  
  104
+                          end;
  105
+                      _ ->
  106
+                          get_path_value(T, OtherValue)
  107
+                  end
80 108
          end
81 109
    end.
82 110
 

0 notes on commit b7db41a

Please sign in to comment.
Something went wrong with that request. Please try again.